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

Maven deploy创建两个不同类型的存储库

许嘉福
2023-03-14

我正在尝试构建一个CI流程,使用Travis CI从github自动将发布工件上传到Maven Central(Sonatype)。基本上,一切都很好,除了在最后;我从maven deploy命令中获得了两个不同的Nexus存储库:一个用于pom和jar;第二个是源代码、javadoc和签名。

我的猜测是,由于中间的元数据上传,他创建了两个存储库:

[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ darksky-client ---
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.5.6/plexus-utils-1.5.6.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.5.6/plexus-utils-1.5.6.pom (5.3 kB at 212 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/1.0.12/plexus-1.0.12.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/1.0.12/plexus-1.0.12.pom (9.8 kB at 392 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.5.6/plexus-utils-1.5.6.jar
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.5.6/plexus-utils-1.5.6.jar (251 kB at 4.0 MB/s)
[INFO] Uploading to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/1.0.1/darksky-client-1.0.1.jar
[INFO] Uploaded to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/1.0.1/darksky-client-1.0.1.jar (41 kB at 4.6 kB/s)
[INFO] Uploading to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/1.0.1/darksky-client-1.0.1.pom
[INFO] Uploaded to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/1.0.1/darksky-client-1.0.1.pom (4.7 kB at 14 kB/s)
[INFO] Downloading from ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/maven-metadata.xml
[INFO] Uploading to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/maven-metadata.xml
[INFO] Uploaded to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/maven-metadata.xml (312 B at 34 B/s)
[INFO] Uploading to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/1.0.1/darksky-client-1.0.1-sources.jar
[INFO] Uploaded to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/1.0.1/darksky-client-1.0.1-sources.jar (26 kB at 65 kB/s)
[INFO] Uploading to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/1.0.1/darksky-client-1.0.1-javadoc.jar
[INFO] Uploaded to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/1.0.1/darksky-client-1.0.1-javadoc.jar (182 kB at 439 kB/s)
[INFO] Uploading to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/1.0.1/darksky-client-1.0.1.jar.asc
[INFO] Uploaded to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/1.0.1/darksky-client-1.0.1.jar.asc (819 B at 7.3 kB/s)
[INFO] Uploading to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/1.0.1/darksky-client-1.0.1.pom.asc
[INFO] Uploaded to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/1.0.1/darksky-client-1.0.1.pom.asc (819 B at 5.9 kB/s)
[INFO] Uploading to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/1.0.1/darksky-client-1.0.1-sources.jar.asc
[INFO] Uploaded to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/1.0.1/darksky-client-1.0.1-sources.jar.asc (819 B at 6.7 kB/s)
[INFO] Uploading to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/1.0.1/darksky-client-1.0.1-javadoc.jar.asc
[INFO] Uploaded to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/1.0.1/darksky-client-1.0.1-javadoc.jar.asc (819 B at 7.1 kB/s)

还我不明白为什么,以及如何修复它。

我的pom。xml如下所示:

<?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>be.skylark.weather</groupId>
    <artifactId>darksky-client</artifactId>
    <version>1.0.1</version>
    <name>darksky-client</name>
    <description>Rest Client library for the darksky API</description>

    <url>https://github.com/skylarkbe/darksky-client/</url>

    <licenses>
        <license>
            <name>GNU GENERAL PUBLIC LICENSE V3</name>
            <url>http://www.gnu.org/licenses/gpl.html</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <developers>
        <developer>
            <name>Romain Van der Keilen</name>
            <email>somemail@gmail.com</email>
        </developer>
    </developers>

    <scm>
        <url>https://github.com/skylarkbe/darksky-client/</url>
        <connection>scm:git:git://github.com/skylarkbe/darksky-client.git</connection>
        <developerConnection>scm:git:git@github.com:skylarkbe/darksky-client.git</developerConnection>
    </scm>

    <issueManagement>
        <system>GitHub</system>
        <url>https://github.com/skylarkbe/darksky-client/issues</url>
    </issueManagement>


    <distributionManagement>
        <snapshotRepository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
        </repository>
    </distributionManagement>

    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <jersey.client.version>2.26-b03</jersey.client.version>
        <junit.jupiter.version>5.4.2</junit.jupiter.version>
        <junit.test.excludes>**/*IntegrationTest.java</junit.test.excludes>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-text</artifactId>
            <version>1.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.6</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-client</artifactId>
            <version>${jersey.client.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-jackson</artifactId>
            <version>${jersey.client.version}</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.6</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>${junit.jupiter.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- To run tests -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <excludes>
                        <exclude>${junit.test.excludes}</exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>release</id>
            <activation>
                <property>
                    <name>release</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <!-- To attach sources -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>3.0.1</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- To generate javadoc -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>3.1.0</version>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- To sign the artifacts -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>1.6</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>

通过travis CI工具的一些附加设置:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">

    <servers>
        <server>
            <!-- Maven Central Deployment -->
            <id>ossrh</id>
            <username>${env.SONATYPE_USERNAME}</username>
            <password>${env.SONATYPE_PASSWORD}</password>
        </server>
    </servers>
    <profiles>
        <profile>
            <id>ossrh</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <gpg.executable>${env.GPG_EXECUTABLE}</gpg.executable>
                <gpg.passphrase>${env.GPG_PASSWORD}</gpg.passphrase>
            </properties>
        </profile>
    </profiles>

</settings>

Travis用于构建的maven命令如下

mvn --settings .travis.settings.xml install -DskipTests=true -Dgpg.skip -Dmaven.javadoc.skip=true -B -V

部署的方法如下

mvn clean deploy --settings .travis.settings.xml -DskipTests=true -Prelease -B

GPG正在正确执行以签署工件;这只是上传到暂存存储库的最后一步,这让我很头疼。。。

提前感谢您的帮助:)

共有2个答案

李辉
2023-03-14

因此,我克隆了您的存储库,将groupId更改为我自己的,并更改了distributionManagement id,并制作了

mvn clean deploy -Prelease -B 

结果是:

如您所见,所有工件都已正确上传。

此外,我只能在日志输出中看到上传到临时存储库:

[INFO] Uploading to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/1.0.1/darksky-client-1.0.1.jar
[INFO] Uploaded to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/1.0.1/darksky-client-1.0.1.jar (41 kB at 4.6 kB/s)
[INFO] Uploading to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/1.0.1/darksky-client-1.0.1.pom
[INFO] Uploaded to ossrh: https://oss.sonatype.org/service/local/staging/deploy/maven2/be/skylark/weather/darksky-client/1.0.1/darksky-client-1.0.1.pom (4.7 kB at 14 kB/s)
[INFO] Downloading from ossrh: https://oss.sonatype.org/service/l

其他日志条目显示正在进行的下载,这些下载来自中央存储库和maven deploy插件的依赖项:

[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ darksky-client ---
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.5.6/plexus-utils-1.5.6.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.5.6/plexus-utils-1.5.6.pom (5.3 kB at 212 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/1.0.12/plexus-1.0.12.pom
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/1.0.12/plexus-1.0.12.pom (9.8 kB at 392 kB/s)
[INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.5.6/plexus-utils-1.5.6.jar
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/1.5.6/plexus-utils-1.5.6.jar (251 kB at 4.0 MB/s)
...

不幸的是我还不明白你的问题。。。

关于我的意思是应该定义您正在使用的所有插件的版本,例如maven-clee-plugin、maven-resources-plugin、maven-install-plugin、maven-部署-plugin等,这些插件在您的pom中没有定义。您已决定不使用可以为您完成此操作的现有父级。您可以看看那个作为建议。

王棋
2023-03-14

这可能更多的是特拉维斯/sonatype配置问题,而不是maven问题。

我终于能够正确上传所有内容;但我必须:

<build>
    <plugins>
        <!-- Disable default maven deploy plugin -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>3.0.0-M1</version>
            <configuration>
                <skip>true</skip>
            </configuration>
        </plugin>
    </plugins>
</build>

然后在我的发布配置文件中:

<!-- Uses Sonatype deploy plugin -->
<plugin>
    <groupId>org.sonatype.plugins</groupId>
    <artifactId>nexus-staging-maven-plugin</artifactId>
    <version>1.6.8</version>
    <extensions>true</extensions>
    <executions>
        <execution>
            <id>default-deploy</id>
            <phase>deploy</phase>
            <goals>
                <goal>deploy</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <serverId>ossrh</serverId>
        <nexusUrl>https://oss.sonatype.org/</nexusUrl>
        <autoReleaseAfterClose>false</autoReleaseAfterClose>
    </configuration>
</plugin>

感谢您的帮助和见解!

 类似资料:
  • 我使用一个Android库,它要求我创建两个类,每个类继承自不同的类 (具有公共基类) 现在我有这个代码: 我必须复制这个类来创建一个扩展,即使我的两个类共享完全相同的代码。 我简化了示例的代码,但重复可能很重要 我决定将代码放在这两个类之外的静态方法中,并在类重写的方法中调用它们,但我认为必须有一种更干净的方法来做到这一点。 你能帮我解决这个问题吗? 和都继承自。

  • 问题内容: 假设我必须创建一个存储ArrayList的Integers数组,并且数组大小为10。 下面的代码可以做到这一点: 问题1: 我认为更合适的代码是 为什么这不起作用? 问题2: 下面两个都编译 有什么区别尽可能的引用声明和关注? 问题答案: 问题1: 基本上,这是Java语言禁止的。Java语言规范中的泛型部分对此进行了介绍。 使用时 您会收到编译器警告,因为以下示例将进行编译(为每行代

  • 问题内容: 我想将元素存储在一个列表中,每个元素具有4个参数,我试图创建一个数组列表,该列表为每个元素存储4个参数,它们是不同类型的: iD:int x位置:浮点 y位置:浮点 名称:字符串 我用: 但是当我使用时: 我得到错误: “ ArrayList类型的add(int,Object)方法不适用于参数(in,float,float)” 我不知道如何能够向ArrayList添加不同类型,有没有办

  • 但是我有两种回购方式 如何创建两个bean,其中一个是用注入的,另一个是用注入的?

  • 我正在尝试合并两个不同类型的列表。我得到了两个不同的API响应从改造在一个android应用程序,第一个列表是一个电影列表定义为 公共类列表{ 我通过以下操作成功地从API中检索到列表 然后,我尝试将一个类型列表和一个类型字符串列表组合起来,以创建一个新类ListingAndImage(字符串是一个URL,我将加载到imageview中) 我的问题是,哪种方式最好将这两个列表组合起来,形成一个列表

  • 显然,在示例中,我将它们设置为字符串属性,但实际上它们是其他类型的。 注意:Object1和Object2实际上是从SOAP服务器所需的XML模型生成的类。所以我不能修改它们。 在我的代码中,我必须访问Object1或Object2的'name'属性,这取决于不同的因素。这个点是一个事件处理程序,所以在某一时刻,它捕获一个用Object1调用的事件,而在其他时间,它捕获一个用Object2调用的事