Java Maven:库的开发和发布版本

Java Maven:库的开发和发布版本,java,maven,Java,Maven,我有一个由3个图书馆组成的项目——让我们称它们为1)婴儿图书馆、2)儿童图书馆和3)成人图书馆。Lib“儿童”依赖于“婴儿”,而“成人”依赖于“儿童” 我想做的是生产: 具有所有(可传递)依赖项的开发版本 为每个库创建独立JAR的生产版本(嵌入依赖项) 我已经有了一个profiledev和一个profilerelease,我知道如何使用ProGuard生成JAR 问题是如何告诉Maven在dev中保留所有依赖项,并在production中忽略它们(可选/提供)?要在开发到部署时具有不同的依赖

我有一个由3个图书馆组成的项目——让我们称它们为1)婴儿图书馆、2)儿童图书馆和3)成人图书馆。Lib“儿童”依赖于“婴儿”,而“成人”依赖于“儿童”

我想做的是生产:

  • 具有所有(可传递)依赖项的开发版本
  • 为每个库创建独立JAR的生产版本(嵌入依赖项)
我已经有了一个profile
dev
和一个profile
release
,我知道如何使用ProGuard生成JAR


问题是如何告诉Maven在
dev
中保留所有依赖项,并在
production
中忽略它们(可选/提供)?

要在开发到部署时具有不同的依赖项,可以使用Maven配置文件

因此,在开发时,您将使用类似于
mvn-Pdev compile的东西

当你说“独立jar”时,听起来你是指一个包含所有依赖项的jar


或者

以下是我最终使用的:

  • 父POM定义了一个配置文件
    release
    ,该配置文件配置了
    proguard插件
    (装箱一个大罐子)和
    安装插件
    (将release工件放在repo中)

  • lib baby POM只调用
    部分中的2个插件

  • lib-child-POM还指定了一个
    dev
    概要文件,其中定义了对
    lib-baby
    的依赖关系。在发布概要文件中,这个依赖项有一个
    可选的
    标记,并包含在大JAR中

在默认情况下运行时,将创建libs
com.company.dev:lib baby
com.company.dev:lib子项
(包括它们的依赖项)

使用
-prerelease
运行时,会创建libs
com.company:lib baby
com.company:lib child
(独立libs[无任何依赖项])-唯一的副作用是覆盖默认工件(.*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>

com公司
库父项
聚甲醛
自由婴儿
自由儿童
自由成年人
释放
释放
com.pyx4me
proguard maven插件
...
${project.build.finalName}.jar
${project.build.finalName}-release.jar
....
真的
org.apache.maven.plugins
maven安装插件
安装版本
安装文件
target/${project.build.finalName}-release.jar
com公司
...
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>
<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>

com.company.dev
自由婴儿
罐子
com公司
库父项
释放
com.pyx4me
proguard maven插件
org.apache.maven.plugins
maven安装插件
安装版本
安装
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>
<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>

com.company.dev
自由儿童
罐子
com公司
库父项
发展
真的
com.company.dev
自由婴儿
释放
com.company.dev
自由婴儿
1
真的
com.pyx4me
proguard maven插件
com.company.dev
自由婴儿
org.apache.maven.plugins
maven安装插件
安装版本
安装