gradle-release build and publish non-snapshot artifacts

3.3k views Asked by At

I have a multi-module project. And, I want to be able do just do gradle release and get all artifacts of all modules released. One of the problems is that when I include the plugins, I get Task with name 'build' not found in root project ' So, following some advice on the internet I created a build task and added a bunch of dependencies on it:

plugins {
    id "net.researchgate.release" version "2.6.0"
}
defaultTasks 'clean', 'assemble'

def repoUrl = System.env.REPO ?: "https://company.jfrog.io/company/maven"
allprojects {
    repositories {
        mavenCentral()
        jcenter()
        maven {
            url 'https://dl.bintray.com/palantir/releases'
        }
        maven {
            credentials {
                username System.env.REPO_USER
                password System.env.REPO_PASS
            }
            url repoUrl
            name 'company'
        }
    }
}


task build{}


subprojects { thisProject ->

    apply plugin: 'java'
    apply plugin: 'maven'
    apply plugin: 'checkstyle'
    apply plugin: 'maven-publish'
    apply plugin: 'findbugs'

    build.dependsOn "${thisProject}:build"

    publishing {
        repositories {
            maven {
                credentials {
                    username System.env.REPO_USER
                    password System.env.REPO_PASS
                }
                url repoUrl
                name 'company'
            }
        }
        publications {
            "-$thisProject.name-"(MavenPublication) {
                from components.java
            }
        }
    }


    sourceCompatibility = 1.8 // java 8
    targetCompatibility = 1.8

    task sourcesJar(type: Jar, dependsOn: classes) {
        classifier = 'sources'
        from sourceSets.main.allSource
    }

    task javadocJar(type: Jar, dependsOn: javadoc) {
        classifier = 'javadoc'
        from javadoc.destinationDir
    }

    artifacts {
        archives sourcesJar
        archives javadocJar
    }

}
tasks.each {println(it)}
afterReleaseBuild.dependsOn tasks.publish

when I run gradle tasks --all I get

task ':afterReleaseBuild'
task ':beforeReleaseBuild'
task ':build'
task ':checkCommitNeeded'
task ':checkSnapshotDependencies'
task ':checkUpdateNeeded'
task ':commitNewVersion'
task ':confirmReleaseVersion'
task ':createReleaseTag'
task ':createScmAdapter'
task ':initScmAdapter'
task ':preTagCommit'
task ':release'
task ':runBuildTasks'
task ':unSnapshotVersion'
task ':updateVersion'

"release" works. That is to say it bumps versions, tags, strips the "-SNAPSHOT" off, etc. But, there is a step missing here (and it could totally be my ignorance), but upon stripping the "-SNAPSHOT" from the version I need it to build the artifacts and publish them. This is like the maven release process but without the artifact upload. I am currently using gradle publish and not maven upload.

Caveats: Very new to gradle but not java Can someone tell me what I am missing? _

1

There are 1 answers

0
Yaroslav On

You just can try to remove build task from the relesae plugin configuration. buildTasks = [] works fine for me.

release {
    ...
    tagTemplate = '${version}'
    versionPropertyFile = 'gradle.properties'
    buildTasks = []
    ...    
}