我有一个由3个库组成的项目 - 让我们称之为1)BABY,2)CHILD和3)ADULT。 Lib“CHILD”依赖于“BABY”,“ADULT”依赖于“CHILD”。
我想做的是产生:
我已经拥有个人资料dev
和个人资料release
,而且我知道如何使用ProGuard生成JAR。
问题是如何告诉Maven将所有依赖项保留在dev
中并忽略它们(可选/提供){1}}
答案 0 :(得分:2)
要在开发部署时使用不同的依赖关系,可以使用maven配置文件。
http://maven.apache.org/guides/introduction/introduction-to-profiles.html
因此,在开发时,您会使用类似mvn -Pdev compile
当你说“独立jar”时,它听起来像是指一个包含所有依赖项的jar。
How can I create an executable JAR with dependencies using Maven?
答案 1 :(得分:0)
这是我最终使用的内容:
父POM定义了一个配置文件release
,用于配置proguard plugin
(一个大JAR的箱子)和install plugin
(将释放工件放置在仓库中)。
lib-baby POM只需调用<build>
部分中的2个插件。
lib-child POM还指定了dev
个人资料,其中定义了对lib-baby
的依赖关系。在发布配置文件中,此依赖项具有optional
标记,并包含在大型JAR中。
最后在默认情况下运行时,会创建lib com.company.dev:lib-baby
和com.company.dev:lib-child
(包括它们的依赖项)。
当使用-Prelease
运行时,创建了lib com.company:lib-baby
和com.company:lib-child
(独立库[没有任何依赖关系]) - 唯一的副作用是默认工件(。* dev)是覆盖:(
<强>父强>:
<project>
<groupId>com.company</groupId>
<artifactId>lib-parent</artifactId>
<packaging>pom</packaging>
<modules>
<module>lib-baby</module>
<module>lib-child</module>
<module>lib-adult</module>
</modules>
<profiles>
<profile>
<id>release</id>
<activation>
<property>
<name>release</name>
</property>
</activation>
<build>
<pluginManagement>
<plugins>
<!-- aggregate to one big jar -->
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<executions>
...
</executions>
<configuration>
<injar>${project.build.finalName}.jar</injar>
<outjar>${project.build.finalName}-release.jar</outjar>
....
</configuration>
</plugin>
<!-- install release version of artifact separately (under com.company) -->
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-release</id>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>
target/${project.build.finalName}-release.jar
</file>
<groupId>com.company</groupId>
...
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
<强> LIB-婴儿强>
<project>
<groupId>com.company.dev</groupId>
<artifactId>lib-baby</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.company</groupId>
<artifactId>lib-parent</artifactId>
</parent>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<!-- produces 'lib-baby-release.jar -->
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
</plugin>
<!-- installs 'lib-baby-release.jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-release</id>
<phase>install</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
<强> LIB-子:强>
<project>
<groupId>com.company.dev</groupId>
<artifactId>lib-child</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.company</groupId>
<artifactId>lib-parent</artifactId>
</parent>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>com.company.dev</groupId>
<artifactId>lib-baby</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>release</id>
<dependencies>
<dependency>
<groupId>com.company.dev</groupId>
<artifactId>lib-baby</artifactId>
<version>1.0</version>
<!-- made optional because will be embedded in standalone jar -->
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<!-- produces 'lib-child-release.jar -->
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<configuration>
<assembly>
<inclusions>
<inclusion>
<groupId>com.company.dev</groupId>
<artifactId>lib-baby</artifactId>
</inclusion>
</inclusions>
</assembly>
</configuration>
</plugin>
<!-- installs 'lib-child-release.jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-release</id>
<phase>install</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>