Maven 2 将maven程序集归档卸载到捆绑模块中
我有几个子模块,比如A,B+C,它们分别生成一个程序集tar.gz和一个模块X,通过将tarball提取到目标目录中,将它们捆绑在一起 现在,使用分类器和module X POM中的type设置我对A、B+C的依赖关系,并使用带有dependencySets的程序集文件。该模块似乎不是在从本地repo中提取tarball,而是在重建它 这会导致问题,因为A、B+C各自有自己的过滤器。当X重建A时,它将不进行过滤。我希望maven从我的repo中获取A-distro.tar.gz,或者如果不存在重建A,将其放入repo中,然后让X使用它 这是我正在使用的assembly.xml文件。使用坐标时,我无法使模块集正常工作,因此我采用了以下方法:Maven 2 将maven程序集归档卸载到捆绑模块中,maven-2,Maven 2,我有几个子模块,比如A,B+C,它们分别生成一个程序集tar.gz和一个模块X,通过将tarball提取到目标目录中,将它们捆绑在一起 现在,使用分类器和module X POM中的type设置我对A、B+C的依赖关系,并使用带有dependencySets的程序集文件。该模块似乎不是在从本地repo中提取tarball,而是在重建它 这会导致问题,因为A、B+C各自有自己的过滤器。当X重建A时,它将不进行过滤。我希望maven从我的repo中获取A-distro.tar.gz,或者如果不存在重
<assembly>
<id>distro</id>
<formats>
<format>dir</format>
<format>tar.gz</format>
</formats>
<baseDirectory>${project.version}</baseDirectory>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<useTransitiveFiltering>true</useTransitiveFiltering>
<useProjectArtifact>false</useProjectArtifact>
<unpack>false</unpack>
<outputDirectory>/lib</outputDirectory>
<excludes>
<exclude>*:tar.gz</exclude>
</excludes>
</dependencySet>
<dependencySet>
<useTransitiveFiltering>true</useTransitiveFiltering>
<useProjectArtifact>false</useProjectArtifact>
<unpack>true</unpack>
<outputDirectory>/</outputDirectory>
<includes>
<include>*:tar.gz</include>
</includes>
</dependencySet>
</dependencySets>
</assembly>
模块1生成具有以下坐标的部件文件:
<dependency>
<groupId>org.test</groupId>
<artifactId>module1</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>distro</classifier>
<type>tar.gz</type>
</dependency>
生成以下文件:
~/mvnrepos/org/test/module1/1.0-SNAPSHOT/module1-1.0-SNAPSHOT-distro.tar.gz
使用以下程序集构建捆绑包时,会拉入并使用tar.gz:
<assembly>
<id>distro</id>
<formats>
<format>dir</format>
<format>tar.gz</format>
</formats>
<baseDirectory>${project.version}</baseDirectory>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<includes>
<include>org.test:module1:tar.gz</include>
</includes>
<useTransitiveFiltering>true</useTransitiveFiltering>
<useProjectArtifact>false</useProjectArtifact>
<unpack>true</unpack>
<unpackOptions>
<excludes>
<exclude>lib/</exclude>
</excludes>
</unpackOptions>
<outputDirectory>lib/</outputDirectory>
</dependencySet>
</dependencySets>
<!-- just includes conf and bin dirs -->
<componentDescriptors>
<componentDescriptor>src/main/assembly/assembly-files.xml</componentDescriptor>
</componentDescriptors>
</assembly>
但是,如果我清除了我的存储库并在根目录下清理了项目,这样tar.gz就被完全删除了,当我更改为bundle dir和mvn安装时,它会失败,因为maven无法解决它需要在没有tar.gz的情况下重建模块1才能获得它。这是我的包pom:
<project>
<parent>
<artifactId>test_parent</artifactId>
<groupId>org.test</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.test</groupId>
<artifactId>bundle</artifactId>
<packaging>pom</packaging>
<name>bundle</name>
<version>1.0-SNAPSHOT</version>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.test</groupId>
<artifactId>module1</artifactId>
</dependency>
<dependency>
<groupId>org.test</groupId>
<artifactId>module2</artifactId>
</dependency>
<dependency>
<groupId>org.test</groupId>
<artifactId>module1</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>distro</classifier>
<type>tar.gz</type>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
我如何让maven认识到必须通过重建模块1来重建程序集
我试图将每个组件保持在一个单独的模块中,这样每个模块都可以作为一个单独的单元进行构建和测试,而不是为了运行任何模块而需要重新构建聚合器。然后,如果需要完整运行,只需将每个程序集tarball解包到bundle/target下的目录中,就可以构建bundle
也许上述内容与主题背道而驰——但这似乎是Sonotype书中maven组装章节的主旨:
不幸的是,sonotype提供的示例在第12章中没有任何内容:-
当然,我可以直接进入ant并使用它,但如果可能的话,我希望纯粹在maven中实现
顺便说一句,maven assembly插件版本是2.2-beta-2。我不确定我是否理解您的问题,所以让我尝试重新表述一下 您有4个项目,A、B、C和X。您将A、B和C定义为X的子项目 构建项目X时,您希望包含项目A、B和C的tar.gz文件 问题是,您只想在需要时构建一个,并从项目中下载它 存储库(如果已存在) 假设我正确地理解了这个问题,我仍然不清楚你期望孩子们是如何有条件地成长的。如果X将其他模块声明为模块,Maven将始终与父模块一起构建它们。如果X将其他构件声明为依赖项,那么它们将只被视为依赖项,因此构建将失败,除非这些构件存在于存储库中,即您已经构建了它们 如果您希望能够在构建过程中实现灵活性,我建议将组装器和聚合器的职责分离到不同的项目中 聚合器只是将项目声明为模块,这样您就可以方便地在一个命令中构建所有项目 您的项目X的组装项目声明了对项目A、B和C的依赖关系。当您构建项目X时,要求其他项目已经构建,但如果在聚合器中构建,则反应器将首先构建它们。然而,如果你独立构建它,你知道其他的都是最新的 关于Maven使用的其他一些要点应该澄清这种方法 Maven存储库是您开发的所有工件的记录。您不需要在构建之间清除本地存储库。它旨在充当所有工件的存储库。因此,如果安装project A,则在重建project A之前,将始终使用该版本 如果必须清除本地存储库,则应将构件部署到远程存储库。有关入门指南,请参阅的相关部分,以便即使清除了本地存储库,也可以将构件合并到project X的构建中 因此,构建项目的工作流是: 在聚合器项目或相关项目A、B或C上运行mvn安装。 项目将安装到本地存储库中。 不要清除本地存储库! 在ProjectX上运行mvn安装,Maven将从存储库中检索依赖项并将它们打包到程序集中。 如果您使用mvn部署,同样的原则也适用,但是因为工件位于远程存储库中,您可以自由地清除本地存储库 为了强调我先前的观点: 没有任何机制可以有条件地构建模块。他们要么建造,要么不建造 't但是,如果不需要,可能会跳过生成的某些步骤,例如编译可能已经在以前的生成中完成 不需要清除本地存储库,如果需要,应该将模块部署到远程存储库,以便可以检索它们。
好的,我应该更清楚我为什么要清算本地回购——我知道这不是构建周期中的正常步骤 我正在清理我的本地回购协议,以模拟如果我第一次尝试构建而远程回购协议上不存在任何内容时会发生的情况。这是因为在签出父+模块时,我需要的所有代码都存在
Parent
\----module1 (includes assembly classifier)
|
\----module2
|
\----bundle
例如,从parentbuilds module1、module2构建带有空repo的build,然后绑定。按此顺序,所有操作都很好:
父级,模块1,模块2,束
但是,如果我有一个空的repos和cd-to-X,那么build-maven无法确定它需要构建依赖于module1和module2的父级,因此如果可能,我希望它按照以下顺序构建:
父级,模块1,模块2,束
我认为这在maven中是不可能的,正如您所说,没有条件模块构建的机制!我以为maven会支持这一点,因为它有关于家长的信息,家长也有关于孩子的信息,但我想我推断的太多了
非常感谢您的回复。与maven一起到达那里,但这就像拔牙一样,很大程度上是因为sonotype手册的风格
ps编辑问题使上下文松散。我不知道是stackoverflow干的。usenet风格第一次就做对了,写下你自己的回复,如果需要,包括对以前回复的引用,在底部发布。编辑之前的帖子会抹去对话的流程——对于某些问题,解决方案的过程和目的地一样有指导意义!最后一段是400个字符:-
我不能按建议把这条评论放进去,因为它超过了600个字符的技术音障
<project>
<parent>
<artifactId>test_parent</artifactId>
<groupId>org.test</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.test</groupId>
<artifactId>bundle</artifactId>
<packaging>pom</packaging>
<name>bundle</name>
<version>1.0-SNAPSHOT</version>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.test</groupId>
<artifactId>module1</artifactId>
</dependency>
<dependency>
<groupId>org.test</groupId>
<artifactId>module2</artifactId>
</dependency>
<dependency>
<groupId>org.test</groupId>
<artifactId>module1</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>distro</classifier>
<type>tar.gz</type>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
Parent
\----module1 (includes assembly classifier)
|
\----module2
|
\----bundle