kas*_*ili 14 maven maven-assembly-plugin maven-jar-plugin
我是maven的新手,花了大约3天时间使用汇编插件生成zip文件,参考http://www.petrikainulainen.net/programming/tips-and-tricks/creating-a-runnable-binary-distribution-with- maven-assembly-plugin /我的项目是多模块的,所以我也提到使用Maven程序集插件管理多模块依赖项
我还有几个效率低下的问题.下面是assembly.xml(我从第一个链接继承)
<assembly>
<id>bin</id>
<!-- Generates a zip package containing the needed files -->
<formats>
<format>zip</format>
</formats>
<!-- Adds dependencies to zip package under lib directory -->
<dependencySets>
<dependencySet>
<!-- Project artifact is not copied under library directory since it is
added to the root directory of the zip package. -->
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
<moduleSets>
<moduleSet>
<!-- Enable access to all projects in the current multimodule build! <useAllReactorProjects>true</useAllReactorProjects> -->
<!-- Now, select which projects to include in this module-set. -->
<includes>
<include>com.XX:YY-main</include>
</includes>
<!--<binaries> <outputDirectory>YY-main/target</outputDirectory> <unpack>false</unpack>
</binaries> -->
</moduleSet>
</moduleSets>
<fileSets>
<!-- Adds startup scripts to the root directory of zip package. The startup
scripts are located to src/main/scripts directory as stated by Maven conventions. -->
<fileSet>
<directory>${project.build.scriptSourceDirectory}</directory>
<outputDirectory>conf</outputDirectory>
<includes>
<include>*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory></outputDirectory>
<includes>
<include>log4j.properties</include>
</includes>
</fileSet>
<!-- adds jar package to the root directory of zip package -->
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory></outputDirectory>
<includes>
<include>*with-dependencies.jar</include>
</includes>
</fileSet>
</fileSets>
Run Code Online (Sandbox Code Playgroud)
下面是pom.xml(主要或主要)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration> <descriptors>
<descriptor>YY-main/src/main/assembly/assembly.xml</descriptor>
<!-- <descriptor>DummyAssembly.xml</descriptor> -->
</descriptors>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
问题:
1)由于在主pom中引用了assembly.xml,因此所有子模块也都被压缩.如何仅指定要压缩的某些子模块,而忽略所有其他子模块.我试图将YY-main/src/main/assembly/assembly.xml从main pom移动到child/submodule pom,并在main中使用dummyassembly.xml,它什么都不做.但这不起作用(可能是因为dummyassembly.xml缺少一些必需的行).尝试了一些东西,但似乎没有任何作用
2)同样在assembly.xml(dependencyset)中,它将所有库复制到"lib"文件夹.我怎么能避免这种情况.我再次根据http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#class_dependencySet尝试了一些事情(排除..)但没有任何效果.
有人可以向我提供具体的陈述,我应该在我的pom或汇编文件中更改以解决1和2谢谢
khm*_*ise 23
您应该更改的基本操作是创建一个单独的模块,您可以在其中执行包装,如下所示.
+-- root (pom.xml)
+--- mod-1 (pom.xml)
+--- mod-2 (pom.xml)
+--- mod-assembly (pom.xml)
Run Code Online (Sandbox Code Playgroud)
mod-assembly遗嘱中的pom 看起来像这样:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.test.parent</groupId>
<artifactId>root</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>dist</artifactId>
<packaging>pom</packaging>
<name>Packaging Test : Distribution</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>module-one</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>module-two</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-bundles</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptors>
<descriptor>proj1-assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
这将解决在每个子节点中运行maven-assembly-plugin的问题以及虚拟描述符的问题.在这里你可以找到这种结构的真实例子.
此外,将模块放在一个文件夹中,将依赖项放在另一个文件夹中,您可以使用如下所示的程序集描述符:
<id>bin</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<useTransitiveDependencies>true</useTransitiveDependencies>
<outputDirectory>lib</outputDirectory>
<unpack>false</unpack>
<excludes>
<exclude>${project.groupId}:*:*</exclude>
</excludes>
</dependencySet>
</dependencySets>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<binaries>
<outputDirectory>modules</outputDirectory>
<unpack>false</unpack>
</binaries>
</moduleSet>
</moduleSets>
Run Code Online (Sandbox Code Playgroud)
我认为如何使用 Maven 组装多模块项目这个帖子可能会用一个例子来回答你的问题。
我对你的问题的回答:
1)您应该在父pom中的build和pluginManagement标签中添加Assembly插件,以便在模块中重用它;上面提到的帖子是关于如何做到这一点的一个很好的例子。您还可以查看在线书籍“Maven:完整参考”的8.6 最佳实践章节,主题 8.6.2。
2)排除标签可能很棘手。再次查看在线书籍“Maven:完整参考”的8.5 控制程序集内容章节。例如,关于dependencySets 的子主题 8.5.4提到了如何微调 dependencySets 的依赖项包含和排除;同样,子主题 8.5.5 现在是关于moduleSets 的,展示了如何在该上下文中使用它。
| 归档时间: |
|
| 查看次数: |
19924 次 |
| 最近记录: |