0
votes

I have two maven repositories one local and one external.

On my local repository, I will publish snapshots and releases. On the external repository, I will publish only releases.

My current code in build.gradle for publishing:

publishing {
    ...

    repositories {
        maven { // Local Nexus Repository
            ...

            def releaseRepoUrl = "...//repository/maven-releases/"
            def snapshotsRepoUrl = "...//repository/maven-snapshots/"

            url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releaseRepoUrl
        }

        maven { // external Nexus Repository (only publish if it is a release)
            ...

            def releaseRepoUrl = "...//repository/maven-releases/"

            url = version.endsWith('SNAPSHOT') ? "" : releaseRepoUrl
        }
    }
}

The problem is that if the url is "" an error occurs what's logical because he can't publish to this url.

How can I skip the publishing on the external repository if it is a SNAPSHOT?

1
Can you wrap the second maven block in if (!version.endsWith('SNAPSHOT')) { - tim_yates
@tim_yates Thank you, it works! Such a simple solution :) - Morchul
Glad to help! Posted it as an answer, so hopefully it can help others in the future :-) - tim_yates

1 Answers

0
votes

You can wrap the second maven block in an if statement like so:

publishing {
    ...

    repositories {
        maven { // Local Nexus Repository
            ...

            def releaseRepoUrl = "...//repository/maven-releases/"
            def snapshotsRepoUrl = "...//repository/maven-snapshots/"

            url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releaseRepoUrl
        }
        if (!version.endsWith('SNAPSHOT')) {
            maven { // external Nexus Repository (only publish if it is a release)
                ...

                def releaseRepoUrl = "...//repository/maven-releases/"

                url = releaseRepoUrl
            }
        }
    }
}