2

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-X.Y.Z.jar were X.Y.Z is the version number. We have an internal tool that can be queried for sanity.

nadavy
  • 1,755
  • 1
  • 18
  • 33
  • 1
    The version `v1.2.X` is not semver like ...if you really like to go to central that's the first thing I would change. Furthermore why do you need to tests them? Don't you have unit/integration tests on your build? – khmarbaise May 18 '20 at 06:06
  • @khmarbaise Thx. Regarding the testing - we test it in end to end tests. After the CI marked it as Sane, we need to deploy. But since it is done in several Jenkins jobs and reused by several components, the only easy way for me is to take the artifact which is marked as "Latest" and "Sane". – nadavy May 18 '20 at 06:30
  • A jenkins job is an alternative? – JRichardsz May 26 '20 at 17:42
  • @JRichardsz Yeah, basically I want to have a "deploy" job that will get the artificat name & version, take it from our internal nexus and publish to Maven Central. – nadavy May 27 '20 at 11:32
  • #1 Is you jenkins able to download artifacts from nexus? #2 Is your jenkins able to push artifacts to maven central? – JRichardsz May 27 '20 at 15:42
  • @JRichardsz Yes and Yes. – nadavy May 28 '20 at 13:45
  • Are you using direct shell scripts in your jenkins job or a kind of plugin to execute maven commands? – JRichardsz May 29 '20 at 00:08
  • I prefer shell but that's not mandatory. – nadavy May 29 '20 at 19:07

2 Answers2

1

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.

nadavy
  • 1,755
  • 1
  • 18
  • 33
0

Let me assume you have not only x.y.z 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.

ursa
  • 4,404
  • 1
  • 24
  • 38