Maven部署会创建两个不同的sonatype存储库

时间:2019-05-11 09:44:12

标签: maven travis-ci sonatype maven-deploy-plugin

我正在尝试使用Travis CI从github将发布工件自动上传到Maven Central(Sonatype)来构建CI流程。基本上,一切都很好,除了最后。我从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 个答案:

答案 0 :(得分:0)

所以我已经克隆了您的存储库,将groupId更改为我自己的,并更改了distributionManagement id并进行了

mvn clean deploy -Prelease -B 

结果是:

enter image description here

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

此外,我只能在您的日志输出中看到上传到暂存库的内容:

[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

其他日志条目显示发生了下载,这些下载是从Central存储库下载的,并且是maven-deploy-plugin的依赖项:

[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-clean-plugin,maven-resources-plugin,maven-install-plugin,maven-deploy-plugin等尚未定义的版本。你的宝您已决定不使用可能为您完成的现有父级。您可能需要使用look in that one as an suggestion

答案 1 :(得分:0)

这可能是一个travis / 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>

终于可以了: NexusArtifactUploaded

感谢您的帮助和见解!