maven 多模块项目:我可以 jar-with-dependencies 吗?
maven multimodule project: can I jar-with-dependencies?
我有一个 maven 项目,有一个主项目 A 和模块 B 和 C。children 继承自 A 的 pom。
A
|
|----B
| |----pom.xml
|
|----C
| |----pom.xml
|
|----pom.xml
它已经为所有模块构建了 jar。有没有办法在这些罐子中包含依赖项?例如。所以我得到 B-1.0-with-dependencies.jar
和 C-1.0-with-dependencies.jar
?我试过设置
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
在 parent pom 中,但它似乎没有做任何事情:构建成功,但我得到了规则,no-dependency 罐子。
我想避免在每个 child pom 中放置一些东西,因为实际上我有 2 个以上的模块。我确定有某种方法可以做到这一点,但似乎无法从 Maven 文档中解决。谢谢!
我就是这样实现的。
在我配置的 aggregator/parent pom 中:
<properties>
<skip.assembly>true</skip.assembly>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<skipAssembly>${skip.assembly}</skipAssembly>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
注意 skip.assembly
属性,默认设置为 true
。这意味着程序集不会在父级上执行,这是有道理的,因为父级不提供任何代码(具有包装 pom
)。
然后,在每个模块中我简单地配置了以下内容:
<properties>
<skip.assembly>false</skip.assembly>
</properties>
这意味着在每个子模块中,跳过被禁用,程序集按照父模块中的配置执行。此外,通过这样的配置,您还可以轻松地跳过某个模块的程序集(如果需要)。
另请注意父级上的程序集配置,我在您提供的配置之上添加了一个execution
,以便在调用mvn clean package
(或mvn clean install
).
我有一个 maven 项目,有一个主项目 A 和模块 B 和 C。children 继承自 A 的 pom。
A
|
|----B
| |----pom.xml
|
|----C
| |----pom.xml
|
|----pom.xml
它已经为所有模块构建了 jar。有没有办法在这些罐子中包含依赖项?例如。所以我得到 B-1.0-with-dependencies.jar
和 C-1.0-with-dependencies.jar
?我试过设置
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
在 parent pom 中,但它似乎没有做任何事情:构建成功,但我得到了规则,no-dependency 罐子。
我想避免在每个 child pom 中放置一些东西,因为实际上我有 2 个以上的模块。我确定有某种方法可以做到这一点,但似乎无法从 Maven 文档中解决。谢谢!
我就是这样实现的。
在我配置的 aggregator/parent pom 中:
<properties>
<skip.assembly>true</skip.assembly>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<skipAssembly>${skip.assembly}</skipAssembly>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
注意 skip.assembly
属性,默认设置为 true
。这意味着程序集不会在父级上执行,这是有道理的,因为父级不提供任何代码(具有包装 pom
)。
然后,在每个模块中我简单地配置了以下内容:
<properties>
<skip.assembly>false</skip.assembly>
</properties>
这意味着在每个子模块中,跳过被禁用,程序集按照父模块中的配置执行。此外,通过这样的配置,您还可以轻松地跳过某个模块的程序集(如果需要)。
另请注意父级上的程序集配置,我在您提供的配置之上添加了一个execution
,以便在调用mvn clean package
(或mvn clean install
).