Java maven在多模块项目中构建具有依赖关系的jar
我知道你是用汇编插件来做这件事的,我试过很多描述符,但都不起作用。我无法理解错误消息的含义 项目架构:Java maven在多模块项目中构建具有依赖关系的jar,java,maven,Java,Maven,我知道你是用汇编插件来做这件事的,我试过很多描述符,但都不起作用。我无法理解错误消息的含义 项目架构: ---sti (parent project containing a pom.xml) -----sti-any23 -----sti-common-util -----sti-kbsearch -----sti-websearch -----sti-main 其中,sti是一个聚合器项目。模块sti main取决于所有其他四个模块 父项目pom.xml如下所示: <?xml ver
---sti (parent project containing a pom.xml)
-----sti-any23
-----sti-common-util
-----sti-kbsearch
-----sti-websearch
-----sti-main
其中,sti是一个聚合器项目。模块sti main取决于所有其他四个模块
父项目pom.xml如下所示:
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>....</groupId>
<artifactId>sti</artifactId>
<version>1.0alpha</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven-install-plugin.version>2.5.2</maven-install-plugin.version>
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
<maven-source-plugin.version>2.2.1</maven-source-plugin.version>
<exec-maven-plugin.version>1.4.0</exec-maven-plugin.version>
<maven-shade-plugin.version>2.3</maven-shade-plugin.version>
</properties>
<modules>
<module>sti-any23</module>
<module>sti-common-util</module>
<module>sti-kbsearch</module>
<module>sti-websearch</module>
<module>sti-main</module>
</modules>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
<configuration>
<mainClass/>
</configuration>
</plugin>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>config/maven-assembly/module.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<!-- TODO: a jarjar format would be better -->
<id>alljars</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
4.0.0
....
性病
1.0alpha
聚甲醛
UTF-8
UTF-8
2.5.2
3.5.1
2.2.1
1.4.0
2.3
sti-any23
公共用途
stikbsearch
sti网络搜索
sti干线
安装
org.apache.maven.plugins
maven源插件
${maven source plugin.version}
附加来源
验证
罐子
org.codehaus.mojo
execmaven插件
${exec maven plugin.version}
真的
org.apache.maven.plugins
maven编译器插件
${maven编译器plugin.version}
1.8
1.8
UTF-8
org.apache.maven.plugins
maven汇编插件
2.5.4
带有依赖项的jar
组装
包裹
单一的
config/maven assembly/module.xml
描述符“config/maven assembly/module.xml”如下所示:
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>....</groupId>
<artifactId>sti</artifactId>
<version>1.0alpha</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven-install-plugin.version>2.5.2</maven-install-plugin.version>
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
<maven-source-plugin.version>2.2.1</maven-source-plugin.version>
<exec-maven-plugin.version>1.4.0</exec-maven-plugin.version>
<maven-shade-plugin.version>2.3</maven-shade-plugin.version>
</properties>
<modules>
<module>sti-any23</module>
<module>sti-common-util</module>
<module>sti-kbsearch</module>
<module>sti-websearch</module>
<module>sti-main</module>
</modules>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
<configuration>
<mainClass/>
</configuration>
</plugin>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>config/maven-assembly/module.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<!-- TODO: a jarjar format would be better -->
<id>alljars</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
奥尔贾尔斯
罐子
假的
/
真的
真的
运行时
我得到的错误是:
[WARNING] Cannot include project artifact: uk.ac.shef.dcs:sti:pom:1.0alpha; it doesn't have an associated file or directory.
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] sti-any23 .......................................... SUCCESS [ 1.709 s]
[INFO] sti-common-util .................................... SUCCESS [ 0.728 s]
[INFO] sti-kbsearch ....................................... SUCCESS [ 1.213 s]
[INFO] sti-websearch ...................................... SUCCESS [ 0.433 s]
[INFO] sti-main ........................................... SUCCESS [ 2.855 s]
[INFO] sti ................................................ FAILURE [ 0.389 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.839 s
[INFO] Finished at: 2016-07-26T19:50:53+01:00
[INFO] Final Memory: 75M/505M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.5.4:single (make-assembly) on project sti: Failed to create assembly: Error creating assembly archive alljars: You must set at least one file. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :sti
[警告]不能包括项目工件:uk.ac.shef.dcs:sti:pom:1.0alpha;它没有关联的文件或目录。
[信息]------------------------------------------------------------------------
[信息]反应堆概要:
[信息]
[信息]sti-any23。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。成功[1.709秒]
[信息]sti通用工具。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。成功[0.728秒]
[信息]sti kbsearch。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。成功[1.213 s]
[信息]sti网络搜索。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。成功[0.433秒]
[信息]sti主管道。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。成功[2.855秒]
[信息]sti。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。故障[0.389秒]
[信息]------------------------------------------------------------------------
[信息]生成失败
[信息]------------------------------------------------------------------------
[信息]总时间:7.839秒
[信息]完成时间:2016-07-26T19:50:53+01:00
[信息]最终内存:75M/505M
[信息]------------------------------------------------------------------------
[错误]无法在项目上执行目标org.apache.maven.plugins:maven程序集插件:2.5.4:single(生成程序集)sti:无法创建程序集:创建程序集存档时出错alljars:必须至少设置一个文件。->[帮助1]
[错误]
[错误]要查看错误的完整堆栈跟踪,请使用-e开关重新运行Maven。
[错误]使用-X开关重新运行Maven以启用完整调试日志记录。
[错误]
[错误]有关错误和可能的解决方案的更多信息,请阅读以下文章:
[错误][帮助1]http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[错误]
[错误]纠正问题后,可以使用命令恢复生成
[错误]mvn-射频:sti
我还尝试了在stackoverflow上找到的许多其他描述符,但它们都不起作用。我想我一定是把一些基本概念弄错了,但我不知道是这样
有什么建议吗。谢谢我从未见过在父项目中使用汇编插件。您的父模块属于
pom
。它的输出只是一个pom
文件。除了POM之外,还有任何物理工件输出是没有意义的
在我看来,您应该将程序集插件声明移动到子模块,并仅作为子模块的一部分执行它。所有其他项目都应声明为此模块的依赖项,从这一点开始,您应该构建程序集。是。或者甚至有一个新模块,其目标是创建程序集。使用来自父级的
maven汇编插件
可以用于汇编,但我显然也更喜欢在现有模块或专用模块中进行汇编。谢谢。我将“packaging”更改为“jar”,删除了“modules”块,并添加了“uk.ac.shef.dcs sti main 1.0alpha”块。它似乎在耍花招。这是正确的吗?我同意@Tunaki的观点,我也希望有一个专用的模块来完成这项工作。如果您使用来自父级的maven assembly插件,它将不会正确地导致先执行父级,这意味着所有其他模块都没有打包。要打包,请始终使用一个独立的模块,该模块依赖于您要打包的所有模块,否则您无法确保之前所有模块都已正确构建。特别是如果您使用多线程之类的东西。。