简体   繁体   中英

Publish from internal nexus to maven central

I have an internal nexus that contains all the artifacts that we build. Once an artifact is tested, I want to take the sane artifact and deploy it to Maven Central without rebuilding it .

I know that I might be able to do that using mvn deploy:deploy-file but it seems complicated. Is there an easy way to do it?

Note: due to historical reasons,we don't use SNAPSHOT versions. All versions are in the style of artifact-name-XYZjar were XYZ is the version number. We have an internal tool that can be queried for sanity.

I've ended using an approach similar to what they have in here: https://central.sonatype.org/pages/manual-staging-bundle-creation-and-deployment.html

So, if I had the following files:

ossrh-test-1.2.pom
ossrh-test-1.2.jar
ossrh-test-1.2-javadoc.jar
ossrh-test-1.2-sources.jar

I've invoked this command for the JAR:

mvn gpg:sign-and-deploy-file -Durl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ -DrepositoryId=ossrh -DpomFile=ossrh-test-1.2.pom -Dfile=ossrh-test-1.2.jar

And the following commands for the sources and JavaDocs:

mvn gpg:sign-and-deploy-file -Durl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ -DrepositoryId=ossrh -DpomFile=ossrh-test-1.2.pom -Dfile=ossrh-test-1.2-sources.jar -Dclassifier=sources
mvn gpg:sign-and-deploy-file -Durl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ -DrepositoryId=ossrh -DpomFile=ossrh-test-1.2.pom -Dfile=ossrh-test-1.2-javadoc.jar -Dclassifier=javadoc

Last but not least, since I had to create fake sources and javadoc jars I've just taken a jar, unzipped it, put a readme file inside of it instead of the old content, updated the manifest and zipped it again. Then I've uploaded it as my fake sources/javadoc jars.

Let me assume you have not only xyz version of binaries, but also scm tag for this version.

If so, you can give a try to the following CI job:

<scm> checkout <YOUR TAG>
<scm> clean -d -x -f

mvn maven-dependency-plugin:get -Pcustom-deployment -DexecutionId=resolve-sane-binaries
mvn maven-deploy-plugin:deploy -Pcustom-deployment -DexecutionId=deploy-sane-binaries

with profile in your pom.xml:

<profiles>
    <profile>
        <id>custom-deployment</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>3.1.2</version>
                    <executions>
                        <execution>
                            <id>resolve-sane-binaries</id>
                            <goals>
                                <goal>get</goal>
                            </goals>
                            <configuration>
                                <artifactItems>
                                    <artifactItem>
                                        <groupId>${project.groupId}</groupId>
                                        <artifactId>${project.artifactId}</artifactId>
                                        <version>${project.version}</version>
                                        <type>${project.packaging}</type>
                                        <outputDirectory>${project.build.directory}</outputDirectory>
                                        <destFileName>${project.build.finalName}</destFileName>
                                    </artifactItem>
                                    ...
                                </artifactItems>
                                ...
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                    <executions>
                        <execution>
                            <id>deploy-sane-binaries</id>
                            <goals>
                                <goal>deploy-file</goal>
                            </goals>
                            <configuration>
                                ...
                            </configuration>
                        </execution>
                    <executions>
                <plugin>
            </plugins>

It's just an idea, not a code I've really tested. But hope it'll help.

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