gradle-release icon indicating copy to clipboard operation
gradle-release copied to clipboard

snapshot dependency problem on multiproject using maven-publish plugin

Open citizenkahn opened this issue 8 years ago • 8 comments

Do you know how to get publish to work with maven-publish plugin because when I use the release-plugin 2.40 I'm seeing my 2nd subproject which depends upon my first using a SNAPSHOT.

root build.gradle gradle.properties version=1.0.0-SNAPSHOT /A build.gradle gradle.properties version=1.0.0-SNAPSHOT /B build.gradle dependencies { compile project(":A") gradle.properties version=1.0.0-SNAPSHOT

It looks like root builds and publishMavenJavaPublicationToReleasesRepository first setting project version to next release SNAPSHOT prior to starting on the sub projects. Parent version impacts B's ability to select correct version and I wind up with: root: 1.0.0 A: 1.0.0 B: 1.0.0 depends on A 1.0.1-SNAPSHOT

(concrete example: https://github.com/citizenkahn/gradle-release-examples/tree/master/multi-project-cross-project-dependency-single-version)

I know there's a workaround but I've yet to find it.

COMMAND

gradle clean release -Prelease.useAutomaticVersion=true

ERROR

`Execution failed for task ':subproject2:checkSnapshotDependencies'.

Snapshot dependencies detected: subproject2: [my.examples:subproject1:1.0.8-SNAPSHOT] `

citizenkahn avatar Jul 01 '16 18:07 citizenkahn

+1, I have the same issue. Any solution yet?

myanything avatar Feb 21 '17 04:02 myanything

Hey, sorry overseen that issue for some reason :/ I don't have a solution in my mind for that problem now and we won't fix it in the near future i think as we don't rely on such a setup. I can only recommend using the multi-project-single-version setup. We are using it a lot but in our case we don't apply java or similar to the root project. The multi-project-single-version needs an empty buildTask array like buildTasks = [] And what we do is project.tasks.afterReleaseBuild.dependsOn project.getSubprojects().collect({it.getTasks().getByName("uploadArchives")}) to upload the new version for example. But if i get some time i will fix that bug with the buildTask array that should accept tasks and string that are also from other projects

Hillkorn avatar Feb 21 '17 09:02 Hillkorn

@Hillkorn thank you for the suggestion! I will try it out. As mentioned in another issue, so in this way, when we release the whole project, even a subproject does not have any code changes, it will still be released with a new version, right?

myanything avatar Feb 21 '17 16:02 myanything

Yes that is right. It makes sense if you have projects where you separate core components and other stuff in different projects. Then you can add those dependencies with the same version and it's obvious that they are compatible to each other like jackson, logback and many others are doing it.

Hillkorn avatar Feb 21 '17 16:02 Hillkorn

+1 I would also like to see this fixed. I've had the release plugin applied independently to subprojects but this is failing when there is a project depenency, with the SNAPSHOT error as above. Ideally release or publish could feed the correct version as the subcomponents are built. Will use your suggested workaround until then. Thanks.

JakePi3 avatar Feb 21 '17 17:02 JakePi3

@Hillkorn that is fair! thank you!

myanything avatar Feb 21 '17 17:02 myanything

This aproach seem to work well for me. Subproject dependencies are published before main module, with -SNAPSHOT removed from their versions. The issue with pretag commit message may be worked around with a couple of mustRunAfter on commit tasks.

        project.afterEvaluate {
            project.configurations.compile.dependencies
                    .findAll({ it instanceof ProjectDependency })
                    .each({ d ->
                ProjectDependency p = d as ProjectDependency
                project.tasks.release.tasks.each { String t ->
                    t = t.substring(t.lastIndexOf(Project.PATH_SEPARATOR) + 1)
                    project.tasks.getByName(t).dependsOn p.dependencyProject.tasks.getByName(t)
                }
            })
        }

If B depends on A, publish A and B with ./gradlew :clean :B:release -Prelease.useAutomaticVersion=true

amaslak avatar May 12 '17 17:05 amaslak

Can anyone point me to a gradle build with a workaround for this?

We have a multi-project build where the root project isn't released, and there are dependencies between sub-projects. I'm running into all sorts of issues getting this working with maven-publish plugin.

nigelcharman avatar Nov 18 '17 22:11 nigelcharman