简体   繁体   中英

Maven deploy creates two different sonatype repositories

I'm trying to build a CI process with an automatic upload of release artifacts to Maven Central (Sonatype) from github using Travis CI. Basically, everything works fine, except at the end ; I get two different Nexus repositories from my maven deploy command : one for the pom and the jar ; a second with the sources, javadoc and signatures.

My guess is that he creates two repositories because of the metadata upload in the middle :

[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)

Still ; I don't understand why, and how to fix it.

My pom.xml looks like this:

<?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>

With some additional settings for the travis CI tool:

<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>

The maven command Travis use to build is the following

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

The one for the deployment is the following

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

GPG is executing properly to sign the artifacts ; it's only the very last step for uploading to the staging repository to is giving me headaches...

Thanks in advance for the help :)

So I have cloned your repository change the groupId to my own and changed the distributionManagement id's and made

mvn clean deploy -Prelease -B 

And the result is:

在此处输入图片说明

As you can see all artifacts are correctly uploaded.

Furthermore I can only see uploads to Staging repository in your log output:

[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

The other log entries show that downloads occuring which are downloads from Central repository and dependencies of the 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)
...

So unfortunately I don't understand your problem yet...

About the versions I meant that should define all plugins you are using which are for example maven-clean-plugin, maven-resources-plugin, maven-install-plugin, maven-deploy-plugin etc. which have not defined in your pom. You have decided not to use an existing parent which could have done that for you. You might take a look in that one as an suggestion .

Probably this was more a travis / sonatype configuration issue more than a maven issue.

I was finally able to upload everything properly ; but I had to:

<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>

Then in my release profile :

<!-- 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>

And it is finally OK : NexusArtifact已上传

Thanks for the help and insights !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM