当前位置: 首页 > 知识库问答 >
问题:

同时使用增强扁平插件和增强着色插件

郑茂勋
2023-03-14

如何同时使用maven-flatten-plugin和maven-shade-plugin?

我使用修订版sha1变更列表来管理多模块项目的版本。

为了部署可共同消耗的工件,我使用maven-flatten-plugin生成一个扁平的pom,使${revision}成为实际值。

但是maven-shade-plugin在${修订版}不变的情况下生成了一个减少的pom。

如何指定 maven-shade-插件以使用扁平化的 pom 来减少 pom。

共有3个答案

周育
2023-03-14

好吧,这很有趣

这看起来可以正常工作,并使阴影pom文件变平,而不是根文件

即使指定了阶段,订购也非常导入 - 安装和释放的pom和jar是阴影罐,而扁平的pom

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <executions>
                    <execution>
                        <id>shade</id>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <createDependencyReducedPom>true</createDependencyReducedPom>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>flatten-maven-plugin</artifactId>
                <version>1.2.5</version>
                <configuration>
                    <updatePomFile>true</updatePomFile>
                    <flattenedPomFilename>flatter.pom</flattenedPomFilename>
                </configuration>
                <executions>
                    <execution>
                        <id>flatten22</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>flatten</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>flatten.clean22</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>


<plugin>
                <groupId>com.coderplus.maven.plugins</groupId>
                <artifactId>copy-rename-maven-plugin</artifactId>
                <version>1.0</version>
                <executions>
                    <execution>
                        <id>copy-file</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <sourceFile>flatter.pom</sourceFile>
                            <destinationFile>dependency-reduced-pom.xml</destinationFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

严阳夏
2023-03-14

我在${revision}属性上遇到了同样的问题,但使用了该选项

https://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html

马峻
2023-03-14

我今天遇到了同样的问题,我在网络上没有找到真正的解决方案。虽然PaulT的建议可能对某些人有效,但我发现这是不可接受的,因为尽管设置了,但传递依赖项仍然没有包含在生成的pom中。

我能够通过简单地改变扁平阴影之间的执行顺序来解决这个问题。你只需要确保扁平化阴影后运行。如果您已经在父 pom 中定义了 flatten 插件,只需在具有相同执行 ID 的聚合器项目上添加相同的插件定义即可。

之前(原始订单):

之后(修订订单):

例子:

>

  • 父项目(POM)

    <?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>com.ibasco.test</groupId>
        <artifactId>ucgd-parent</artifactId>
        <packaging>pom</packaging>
        <version>${revision}</version>
    
        <properties>
            <revision>2.0.0-alpha</revision>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
    
        <modules>
            <module>module-one</module>
            <module>module-two</module>
            <module>module-three</module>
            <module>assembly</module>
        </modules>
    
        <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-shade-plugin</artifactId>
                        <version>3.2.1</version>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>flatten-maven-plugin</artifactId>
                        <version>1.1.0</version>
                        <configuration>
                            <updatePomFile>true</updatePomFile>
                            <flattenMode>resolveCiFriendliesOnly</flattenMode>
                        </configuration>
                    </plugin>
                </plugins>
            </pluginManagement>
    
            <plugins>
                <!-- Flatten -->
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>flatten-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>flatten</id>
                            <phase>package</phase>
                            <goals>
                                <goal>flatten</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>flatten.clean</id>
                            <phase>clean</phase>
                            <goals>
                                <goal>clean</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </project>
    

    聚合项目(POM)

    <?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">
        <parent>
            <artifactId>ucgd-parent</artifactId>
            <groupId>com.ibasco.test</groupId>
            <version>${revision}</version>
        </parent>
        <modelVersion>4.0.0</modelVersion>
    
        <artifactId>ucg-display</artifactId>
        <packaging>jar</packaging>
    
        <dependencies>
            <dependency>
                <groupId>com.ibasco.test</groupId>
                <artifactId>module-two</artifactId>
            </dependency>
            <dependency>
                <groupId>com.ibasco.test</groupId>
                <artifactId>module-one</artifactId>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
    
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <!-- A little workaround to disable the jar warning -->
                        <classesDirectory>src</classesDirectory>
                        <excludes>
                            <exclude>**</exclude>
                        </excludes>
                    </configuration>
                </plugin>
                <!-- Javadoc -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>aggregate-javadocs</id>
                            <phase>package</phase>
                            <goals>
                                <goal>aggregate-jar</goal>
                            </goals>
                            <configuration>
                                <includeDependencySources>true</includeDependencySources>
                                <dependencySourceIncludes>
                                    <dependencySourceInclude>com.ibasco.test:*</dependencySourceInclude>
                                </dependencySourceIncludes>
                                <dependencySourceExcludes>
                                    <dependencySourceExclude>com.ibasco.test:module-three</dependencySourceExclude>
                                </dependencySourceExcludes>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <!-- Shade plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
                                <createSourcesJar>true</createSourcesJar>
                                <shadedArtifactAttached>false</shadedArtifactAttached>
                                <createDependencyReducedPom>true</createDependencyReducedPom>
                                <!-- Make sure the transitive dependencies are written to the generated pom under <dependencies> -->
                                <promoteTransitiveDependencies>true</promoteTransitiveDependencies>
                                <artifactSet>
                                    <includes>
                                        <include>com.ibasco.test:module-one</include>
                                        <include>com.ibasco.test:module-two</include>
                                    </includes>
                                </artifactSet>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <!-- Flatten -->
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>flatten-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>flatten</id>
                            <phase>package</phase>
                            <goals>
                                <goal>flatten</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </project>
    

    输出:

        <?xml version="1.0" encoding="UTF-8"?>
        <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <modelVersion>4.0.0</modelVersion>
            <parent>
                <groupId>com.ibasco.test</groupId>
                <artifactId>ucgd-parent</artifactId>
                <version>2.0.0-alpha</version>
            </parent>
            <groupId>com.ibasco.test</groupId>
            <artifactId>ucg-display</artifactId>
            <version>2.0.0-alpha</version>
            <dependencies>
                <dependency>
                    <groupId>org.apache.commons</groupId>
                    <artifactId>commons-lang3</artifactId>
                    <version>3.9</version>
                    <scope>compile</scope>
                    <optional>false</optional>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-jar-plugin</artifactId>
                        <configuration>
                            <classesDirectory>src</classesDirectory>
                            <excludes>
                                <exclude>**</exclude>
                            </excludes>
                        </configuration>
                    </plugin>
                    <plugin>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>aggregate-javadocs</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>aggregate-jar</goal>
                                </goals>
                                <configuration>
                                    <includeDependencySources>true</includeDependencySources>
                                    <dependencySourceIncludes>
                                        <dependencySourceInclude>com.ibasco.test:*</dependencySourceInclude>
                                    </dependencySourceIncludes>
                                    <dependencySourceExcludes>
                                        <dependencySourceExclude>com.ibasco.test:module-three</dependencySourceExclude>
                                    </dependencySourceExcludes>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-shade-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>shade</goal>
                                </goals>
                                <configuration>
                                    <createSourcesJar>true</createSourcesJar>
                                    <shadedArtifactAttached>false</shadedArtifactAttached>
                                    <createDependencyReducedPom>true</createDependencyReducedPom>
                                    <promoteTransitiveDependencies>true</promoteTransitiveDependencies>
                                    <artifactSet>
                                        <includes>
                                            <include>com.ibasco.test:module-one</include>
                                            <include>com.ibasco.test:module-two</include>
                                        </includes>
                                    </artifactSet>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>flatten-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>flatten</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>flatten</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </project>
    

  •  类似资料:
    • 本文向大家介绍MySQL 密码增强插件,包括了MySQL 密码增强插件的使用技巧和注意事项,需要的朋友参考一下 介绍 以前没有太注意MySQL密码安全策略的配置方法,只是人为了将密码设为复杂密码,但是没有找到配置的方法,今天姜承尧的微信公众号正好发布了一篇关于这个的文章,所以在这里也顺便将方法写下来。首先该功能是在5.5以后的mysql版本才引入的插件,默认源码安装和二进制安装都没有启用该功能,如

    • 这是一个VB6的插件,为VB6提供了增强的搜索支持.

    • 插件可以增加 Vue 的全局/实例属性和组件选项。在这些情况下,在 TypeScript 中制作插件需要类型声明。庆幸的是,TypeScript 有一个特性来补充现有的类型,叫做模块补充 (module augmentation)。 例如,声明一个string类型的实例属性$myProperty: // 1. 确保在声明补充的类型之前导入 'vue' import Vue from 'vue'

    • 我正在逐个迭代字符串对象列表中的元素: 在这里,每次我调用list上的get()时,列表都会从其一端一直迭代到第i个元素——因此上面循环的复杂性是O(n^2)。 是a.)对于增强型for循环,与上面相同,还是b.)对于循环,将指针保持在最后一个指针所在的位置,因此下面循环的复杂性是O(n)? 如果上面的情况(b)——我想是这样的——在列表上使用迭代器有什么好处吗。这是简单的迭代--没有回头路 蒂亚

    • 问题内容: Hibernate Gradle插件等效于Hibernate Gradle,并提供了构建时代码增强功能。在官方的文档不提线。如果我按照指南的指示去做,我会得到: 找不到方法hibernate()作为参数… 我尝试用(如该线程所示)和(如该测试所示)猜测插件名称,但这只是说具有该ID的插件是未知的。 是否有人成功设置了此插件? 我的build.gradle如下: 与移动尝试到根,和没有有

    • 问题内容: 在我的NativeScript项目中,我想包含RecyclerViewAndroid支持库中的内容。我将依赖项包括在: 从git issue#2295和其他相关问题中,我读到tns-platform-declarations可以提供本机android / ios库的定义文件的内容。所以我安装了它们并遵循了tns平台声明文档 我想编译以下示例代码段: 声明var android以上类似内