2009-07-27 38 views
3

我想要做的是创建具有所有依赖关系的应用程序的源代码分发并将其刻录到DVD上。 所以我可以在100年内建立它(好吧,你知道我的意思是......)。没有在线依赖库或Maven插件!如何使用自我可持续的maven构建创建源代码发布?

我知道Ant会更好,但我在我的项目中使用maven。我不打算为此转而使用Ant,我正在问如何用maven做到这一点。或者,如果有一种方法可以产生自我可持续的Ant构建,那么我可以把它放在DVD上,这也会很棒。 (有ant:ant插件,但它只是产生的Ant build.xml指向依赖于本地Maven回购)

我采取的方法是,我想创建特殊的本地资源库,我可以把DVD,然后建立项目mvn -o -Dmaven.repo.local=repo/on/dvd。我试图用dependency:copy-dependenciesuseRepositoryLayout参数设置为true。但它不复制我的构建依赖于的怪异插件...

回答

3

我能想到包括插件的唯一方法是在命令行上为构建指定不同的本地存储库,并确保所有下载依赖源等,然后创建一个包含项目内容和自定义存储库的存档。

下载源代码和javadocs(将它们下载到项目的目标目录,我们从归档中排除它们,因为它们也将位于本地存储库中)。程序集描述符将项目内容和本地存储库捆绑到一个(非常大)的存档中。

请注意,处理全部在配置文件中,因为您确实不希望在每个构建版本上运行这些处理。如果临时本地存储库位于目标目录中,那么可以使用mvn clean清理干净。 要启动情景做类似如下:

mvn package -Parchive -Dmaven.repo.local=.\target\repo 

这里的POM:

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>name.seller.rich</groupId> 
    <artifactId>test-archive</artifactId> 
    <version>0.0.1</version> 
    <dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.5</version> 
     <scope>test</scope> 
    </dependency> 
    </dependencies> 
    <profiles> 
    <profile> 
     <id>archive</id> 
     <build> 
     <plugins> 
      <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <executions> 
       <execution> 
       <id>sources</id> 
       <phase>pre-package</phase> 
       <goals> 
        <goal>copy-dependencies</goal> 
       </goals> 
       <configuration> 
        <classifier>sources</classifier> 
        <failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact> 
        <!--the target directory won't be included, but the sources will be in the repository--> 
        <outputDirectory>${project.build.directory}/sources</outputDirectory> 
       </configuration> 
       </execution> 
       <execution> 
       <id>javadocs</id> 
       <phase>pre-package</phase> 
       <goals> 
        <goal>copy-dependencies</goal> 
       </goals> 
       <configuration> 
        <classifier>javadoc</classifier>      <failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact> 
        <outputDirectory>${project.build.directory}/javadocs</outputDirectory> 
       </configuration> 
       </execution> 
      </executions> 
      </plugin> 
      <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>2.2-beta-4</version> 
      <executions> 
       <execution> 
       <phase>package</phase> 
       <goals> 
        <goal>single</goal> 
       </goals> 
       <configuration> 
        <descriptors> 
        <descriptor>src/main/assembly/archive.xml</descriptor> 
        </descriptors> 
       </configuration> 
       </execution> 
      </executions> 
      </plugin>  
     </plugins> 
     </build> 
    </profile> 
    </profiles> 
</project> 

而这里的组件:

<assembly> 
    <id>archive</id> 
    <formats> 
    <format>zip</format> 
    </formats> 
    <fileSets> 
    <fileSet> 
    <directory>${project.basedir}</directory> 
    <outputDirectory>/</outputDirectory> 
     <excludes> 
     <exclude>target/**</exclude> 
     </excludes> 
    </fileSet> 
    <fileSet> 
    <directory>${maven.repo.local}</directory> 
    <outputDirectory>repo</outputDirectory> 
    </fileSet> 
    </fileSets> 
</assembly> 
+0

+1有趣的答案。我可能需要一些时间... – KLE 2009-09-06 09:16:15

0

我没有一个完整的答案。上次我看到这个时,我认为在构建开始时(或使用单独的一个)清除localRepository并运行mvn dependency:go-offline

如果您真的很热衷,那么您还需要将maven本身和JDK捆绑到发行版中。这可能会超出纯maven版本的范围。

1

关注此:

你想创建一个Maven项目 包括支持脚本, 配置文件的二进制 分布,以及所有运行时: Maven Assembly Plugin

从主页报价 依赖关系?您需要使用装配插件 为您的项目创建 分配。

它可以很好地配置。我特别用它来制作带有嵌入式码头服务器和用户文档的Web应用程序的自运行演示版本。

相关问题