Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven 2 如何使用自我可持续的maven build创建源代码分发?_Maven 2_Build Process_Build - Fatal编程技术网

Maven 2 如何使用自我可持续的maven build创建源代码分发?

Maven 2 如何使用自我可持续的maven build创建源代码分发?,maven-2,build-process,build,Maven 2,Build Process,Build,我想做的是创建我的应用程序的源代码分发版和所有依赖项,并将其刻录到DVD上这样我可以在100年内建造它(好吧,好吧,你知道我的意思…)。没有对库或maven插件的在线依赖 我知道Ant会更好,但我在项目中使用maven。我不会仅仅因为这个而切换到Ant,我想问的是如何使用maven实现这一点。或者,如果有一种方法可以产生自我可持续的蚂蚁构建,我可以把它放在DVD上,那也太好了。 (有ant:ant插件,但它只生成指向本地maven repo的依赖项的ant build.xml) 我所采取的方法是

我想做的是创建我的应用程序的源代码分发版和所有依赖项,并将其刻录到DVD上这样我可以在100年内建造它(好吧,好吧,你知道我的意思…)。没有对库或maven插件的在线依赖

我知道Ant会更好,但我在项目中使用maven。我不会仅仅因为这个而切换到Ant,我想问的是如何使用maven实现这一点。或者,如果有一种方法可以产生自我可持续的蚂蚁构建,我可以把它放在DVD上,那也太好了。 (有
ant:ant
插件,但它只生成指向本地maven repo的依赖项的ant build.xml)


我所采取的方法是,我想创建一个特殊的本地存储库,我可以把它放在DVD上,然后用
mvn-o-Dmaven.repo.local=repo/on/DVD
构建项目。我试图用
dependency:copy dependencies
useRepositoryLayout
param设置为
true
来创建这样的存储库。但是它不会复制我的构建所依赖的异常maven插件…

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

下面是一个pom,它下载源代码和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>

4.0.0
name.seller.rich
测试档案
0.0.1
朱尼特
朱尼特
4.5
测试
档案文件
org.apache.maven.plugins
maven依赖插件
来源
预包装
复制依赖项
来源
假的
${project.build.directory}/sources
javadocs
预包装
复制依赖项
javadoc错误
${project.build.directory}/javadocs
maven汇编插件
2.2-β-4
包裹
单一的
src/main/assembly/archive.xml
下面是大会:

<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>

档案文件
拉链
${project.basedir}
/
目标/**
${maven.repo.local}
回购

我没有完整的答案。上次我看到这一点时,我认为应该在构建(或使用单独的一个)和运行时清理localRepository

如果您真的很感兴趣,您还需要将maven本身和JDK捆绑到发行版中。这可能会使它超出纯maven构建的范围。

请注意:

引自网页:

是否要创建二进制文件 来自Maven项目的分发 包括支持脚本, 配置文件,以及所有运行时 依赖关系?你需要使用 用于创建 为您的项目分发

这是很好的配置。我特别使用它来制作带有嵌入式jetty服务器和用户文档的web应用程序的自运行演示版本