【问题标题】:Maven artifacts *-classes.jar deployed twice to repository - attachClassesMaven 工件 *-classes.jar 两次部署到存储库 - attachClasses
【发布时间】:2020-11-20 13:36:43
【问题描述】:

我注意到 *-classes.jars 的产生是因为在多模块 maven 项目中的某个模块中设置了 attachClasses 两次,并且因为我们想将政治更改为不部署版本等。两次,它需要修复。问题仅出现在模块中,该模块使用 maven-war-plugin 构建为战争,attachClasses=true 和 affect -classes.jar 仅,其他工件(如源、poms 等)仅部署一次即可。双重上传发生在 maven-deploy-plugin 部署阶段。我已经查看了有效的 POM,但没有任何明显的发现,没有重复的定义、目标等。 项目非常复杂且相互交织,因此我将仅列出 POM 定义中有趣的部分,如果有人知道可能出了什么问题,我会很高兴。

以下命令用于构建:

mvn -P jboss --batch-mode -U -Dmaven.javadoc.skip=true -Dorg.xml.sax.driver=com.sun.org.apache.xerces.internal.parsers.SAXParser -pl '!dist' clean package

在将快照或发布上传到存储库期间出现问题。

在父 POM 中,我有以下几点:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                        <manifest>
                            <mainClass>${start-class}</mainClass> <!-- from Spring Boot -->
                            <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                        <manifestEntries>
                            <Implementation-Build>${buildNumber}</Implementation-Build>
                            <Implementation-Build-Time>${maven.build.timestamp}</Implementation-Build-Time>
                            <Jenkins-Build-Number>${build.number}</Jenkins-Build-Number>
                            <Jenkins-Build-Id>${build.id}</Jenkins-Build-Id>
                            <Jenkins-Build-Tag>${build.tag}</Jenkins-Build-Tag>
                            <Jenkins-Git-Commit>${build.git.commit}</Jenkins-Git-Commit>
                            <Jenkins-Git-Branch>${build.git.branch}</Jenkins-Git-Branch>
                        </manifestEntries>
                    </archive>
                    <excludes>
                        <!-- This is where the exclusion occurs -->
                        <exclude>**/aaa.ear</exclude>
                    </excludes>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <autoVersionSubmodules>true</autoVersionSubmodules>
                    <useReleaseProfile>false</useReleaseProfile>
                    <releaseProfiles>release</releaseProfiles>
                    <goals>deploy</goals>
                </configuration>
            </plugin>

            <!-- build source artifacts by default -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>cz.bsc.g8.rbcz.onb.web.OnbApplication</mainClass>
                        </manifest>
                    </archive>
                    <attach>false</attach>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

在受影响的模块中,我有:

    <profiles>
    <profile>
        <id>for-ear</id>
        <activation>
            <file>
                <exists>pom.xml</exists>
            </file>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>for-ear</id>
                            <goals>
                                <goal>war</goal>
                            </goals>
                            <phase>package</phase>
                            <configuration>
                                <classifier>ear</classifier>
                                <webappDirectory>${project.build.directory}/for-ear</webappDirectory>
                                <!-- in ear log4j2 will be places -->
                                <packagingExcludes>WEB-INF/classes/log4j2.xml</packagingExcludes>
                            </configuration>
                        </execution>
                    </executions>
                    <configuration>
                        <archive>
                            <manifest>
                                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                                <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                            </manifest>
                        </archive>
                        <archiveClasses>true</archiveClasses>
                        <attachClasses>true</attachClasses>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

更新: 从构建中添加了输出,只是一部分,您可以在其中看到无效输出(第 15 行和第 27 行),工件 dsa-web-1.3-20201121.012503-66-classes.jar 已上传两次:

02:25:03  [INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ dsa-web ---
02:25:03  [INFO] Using alternate deployment repository ACD Snapshot Repository::default::http://triton.acdlon.com:8081/nexus/content/repositories/snapshots
02:25:03  [INFO] Downloading from ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/maven-metadata.xml
02:25:03  [INFO] Downloaded from ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/maven-metadata.xml (1.6 kB at 56 kB/s)
02:25:03  [INFO] Uploading to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/dsa-web-1.3-20201121.012503-66.war
02:25:07  [INFO] Uploaded to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/dsa-web-1.3-20201121.012503-66.war (88 MB at 20 MB/s)
02:25:07  [INFO] Uploading to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/dsa-web-1.3-20201121.012503-66.pom
02:25:07  [INFO] Uploaded to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/dsa-web-1.3-20201121.012503-66.pom (15 kB at 672 kB/s)
02:25:07  [INFO] Downloading from ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/maven-metadata.xml
02:25:07  [INFO] Downloaded from ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/maven-metadata.xml (451 B at 5.8 kB/s)
02:25:07  [INFO] Uploading to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/maven-metadata.xml
02:25:07  [INFO] Uploaded to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/maven-metadata.xml (1.6 kB at 67 kB/s)
02:25:07  [INFO] Uploading to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/maven-metadata.xml
02:25:07  [INFO] Uploaded to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/maven-metadata.xml (451 B at 17 kB/s)
02:25:07  [INFO] Uploading to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/dsa-web-1.3-20201121.012503-66-classes.jar
02:25:07  [INFO] Uploaded to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/dsa-web-1.3-20201121.012503-66-classes.jar (509 kB at 10 MB/s)
02:25:07  [INFO] Uploading to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/maven-metadata.xml
02:25:07  [INFO] Uploaded to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/maven-metadata.xml (1.6 kB at 85 kB/s)
02:25:07  [INFO] Uploading to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/dsa-web-1.3-20201121.012503-66-exec.war
02:25:13  [INFO] Uploaded to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/dsa-web-1.3-20201121.012503-66-exec.war (94 MB at 21 MB/s)
02:25:13  [INFO] Uploading to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/maven-metadata.xml
02:25:13  [INFO] Uploaded to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/maven-metadata.xml (1.6 kB at 90 kB/s)
02:25:13  [INFO] Uploading to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/dsa-web-1.3-20201121.012503-66-sources.jar
02:25:13  [INFO] Uploaded to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/dsa-web-1.3-20201121.012503-66-sources.jar (156 kB at 5.2 MB/s)
02:25:13  [INFO] Uploading to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/maven-metadata.xml
02:25:13  [INFO] Uploaded to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/maven-metadata.xml (1.6 kB at 81 kB/s)
02:25:13  [INFO] Uploading to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/dsa-web-1.3-20201121.012503-66-classes.jar
02:25:13  [INFO] Uploaded to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/dsa-web-1.3-20201121.012503-66-classes.jar (509 kB at 9.6 MB/s)
02:25:13  [INFO] Uploading to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/maven-metadata.xml
02:25:13  [INFO] Uploaded to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/maven-metadata.xml (1.6 kB at 73 kB/s)
02:25:13  [INFO] Uploading to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/dsa-web-1.3-20201121.012503-66-ear.war
02:25:17  [INFO] Uploaded to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/dsa-web-1.3-20201121.012503-66-ear.war (88 MB at 21 MB/s)
02:25:17  [INFO] Uploading to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/maven-metadata.xml
02:25:17  [INFO] Uploaded to ACD Snapshot Repository: http://triton.acdlon.com:8081/nexus/content/repositories/snapshots/cz/acdlon/b5/lgdn/dsa-web/1.3-SNAPSHOT/maven-metadata.xml (1.6 kB at 81 kB/s)

【问题讨论】:

  • 附加构建的完整构建输出...
  • 我只添加了一小部分,不幸的是我无法添加完整的输出
  • 输出显示上传完成了两次,这意味着你的 pom 中有一个错误的配置,它在某处绑定了两次类生成......不幸的是,如果没有完整的 pom,就不可能说...... . 此外,这些配置文件“for-ear”看起来很奇怪,我不明白它的用途是什么......?

标签: java maven


【解决方案1】:

我遇到了与发布版本相同的问题,因为在我们的发布工件存储中禁止重新部署(它允许用于 SNAPSHOTS)。

问题在于,在我的 war 项目中,我手动打包了 jar,因为我想从中排除一些文件并且我使用的是 attachClasses=true。

Maven 正在考虑我创建了 2 个 jar 来部署,即使这 2 个 jar 具有相同的路径、名称和分类器。

通过将 attachClasses 设置为 false,我能够同时部署 webapp 的类 jar 和 war,但我需要将 jar 重新打包到 war 中。

规则似乎是:创建工件的每个插件都将注册它以由部署插件部署。 并且部署插件上没有路径重复数据删除,这会导致同一工件的多次部署。

另一方面,我只是偶然发现了一个使用 attachClasses=false 的意外效果,这是在我的这个 webapp 的集成测试项目中,我将类 jar 引用为在 maven 中可以正常工作的依赖项。但在 Eclipse 中,编译类路径有效,但运行时该 jar 中的类不存在(启动 junit 时 Eclipse 中出现 NoClassDefFoundError)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-02
    • 2020-06-24
    • 1970-01-01
    • 2022-07-25
    • 2014-02-15
    • 1970-01-01
    • 2021-03-31
    • 2020-04-10
    相关资源
    最近更新 更多