Unable to get Gradle signing plugin to work with subprojects

Viewed 221

For single projects, it works great. But with subprojects, it either signs but doesn't publish, or publishes but doesn't sign.

There doesn't seem to be any official documentation from Gradle org showing an example of signing subprojects, and they don't seem to use the signing plugin themselves (which is a shame, because the Gradle source code has more than 100 subprojects, which would make for a very good example).

The gist of the problem is that trying to add the signing task in allprojects or subprojects results in Cannot add task 'signArchives' as a task with that name already exists., but any attempt to sign by some other means (for example, by moving it to an include file, and calling apply-from on that file from each project) removes the sign/publish task.

Other plugins/tasks, for example, jacoco, work fine when applied in allprojects or subprojects. This seems to be specific to the signing plugin. It might even be a bug in the signing plugin (shouldn't it namespace each apply with the project to which it is being applied?). I'd settle for a workaround that works.

Googling for an answer only found one other person who had encountered this problem, and that's where I got the include-file solution, except it removes the publish task.

Things I've tried are documented in detail in github, gradle issues 13419. Thus far there has been no response.

2 Answers

Below is working build.xml.

allprojects {
    apply plugin:  'java'
    apply plugin:  'maven-publish'
    apply plugin:  'signing'

    repositories {
        mavenCentral()
    }

    dependencies {
        testImplementation group: 'junit', name: 'junit', version: '4.12'
    }

    signing {
        sign configurations.archives
    }

    build.dependsOn signArchives
}

group 'com.tssp'
version '1.0-SNAPSHOT'

dependencies {
    implementation(project(':sub1'))
    implementation(project(':sub2'))
}

settings.gradle

rootProject.name = 'tSignSubPrj'
include 'sub1'
include 'sub2'

Run log showing the signArchives for sub projects

14:30:39: Executing task 'build --dry-run'...

:sub1:compileJava SKIPPED
:sub1:processResources SKIPPED
:sub1:classes SKIPPED
:sub1:jar SKIPPED
:sub2:compileJava SKIPPED
:sub2:processResources SKIPPED
:sub2:classes SKIPPED
:sub2:jar SKIPPED
:compileJava SKIPPED
:processResources SKIPPED
:classes SKIPPED
:jar SKIPPED
:signArchives SKIPPED
:assemble SKIPPED
:compileTestJava SKIPPED
:processTestResources SKIPPED
:testClasses SKIPPED
:test SKIPPED
:check SKIPPED
:build SKIPPED
:sub1:signArchives SKIPPED
:sub1:assemble SKIPPED
:sub1:compileTestJava SKIPPED
:sub1:processTestResources SKIPPED
:sub1:testClasses SKIPPED
:sub1:test SKIPPED
:sub1:check SKIPPED
:sub1:build SKIPPED
:sub2:signArchives SKIPPED
:sub2:assemble SKIPPED
:sub2:compileTestJava SKIPPED
:sub2:processTestResources SKIPPED
:sub2:testClasses SKIPPED
:sub2:test SKIPPED
:sub2:check SKIPPED
:sub2:build SKIPPED

BUILD SUCCESSFUL in 59ms
14:30:39: Task execution finished 'build --dry-run'.

This was the craziest thing. Respondents said it worked, and it definitely hadn't worked in our project, so I set out to boil our project down into an example, and when trying to do that, the problem didn't reappear. No idea why it didn't work before, but anyway, it works now.

Related