Skip to content

Commit

Permalink
support subprojects with different versions
Browse files Browse the repository at this point in the history
Generates `release` task list with fully-qualified task names, allowing
you to run the `release` task on a single subproject at a time. Expects
you to apply the plugin seperately to each subproject.

Note: this may mean that subprojects can have different VCS, but I
haven't tested that.
  • Loading branch information
christierney authored and danez committed Sep 22, 2015
1 parent a7cb8c3 commit 86980c4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 24 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@ For example, if we wanted to make sure `uploadArchives` is called and succeeds a

### Multi-Project Builds

Support for [multi-project builds](http://gradle.org/docs/current/userguide/multi_project_builds.html) isn't complete, but will work given some assumptions. The gradle-release plugin assumes and expects the following:
Support for [multi-project builds](http://gradle.org/docs/current/userguide/multi_project_builds.html) isn't complete, but will work given some assumptions. The gradle-release plugin assumes and expects that only one version control system is used by both root and sub projects.

1. Only the root|parent project is applying the plugin
2. Only one version is used for root and sub projects
3. Only one version control system is used by both root and sub projects
Apply the plugin separately to each subproject that you wish to release. Release using a qualified task name, e.g.:

./gradlew :sub:release # release a subproject named "sub"
./gradlew :release # release the root project

This means the gradle-release plugin does not support sub projects that have different versions from their parent|root project, and it does not support sub projects that have different version control systems from the parent project.

### Working in Continuous Integration

Expand Down
43 changes: 28 additions & 15 deletions src/main/groovy/net/researchgate/release/ReleasePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,23 @@ class ReleasePlugin extends PluginHelper implements Plugin<Project> {
project.task('release', description: 'Verify project, release, and update version to next.', group: RELEASE_GROUP, type: GradleBuild) {
startParameter = project.getGradle().startParameter.newInstance()

// name tasks with an absolute path so subprojects can be released independently
String p = project.getPath()
p = !p.endsWith(Project.PATH_SEPARATOR) ? p + Project.PATH_SEPARATOR : p;

tasks = [
'createScmAdapter',
'initScmAdapter',
'checkCommitNeeded',
'checkUpdateNeeded',
'unSnapshotVersion',
'confirmReleaseVersion',
'checkSnapshotDependencies',
'runBuildTasks',
'preTagCommit',
'createReleaseTag',
'updateVersion',
'commitNewVersion'
"${p}createScmAdapter" as String,
"${p}initScmAdapter" as String,
"${p}checkCommitNeeded" as String,
"${p}checkUpdateNeeded" as String,
"${p}unSnapshotVersion" as String,
"${p}confirmReleaseVersion" as String,
"${p}checkSnapshotDependencies" as String,
"${p}runBuildTasks" as String,
"${p}preTagCommit" as String,
"${p}createReleaseTag" as String,
"${p}updateVersion" as String,
"${p}commitNewVersion" as String
]
}

Expand All @@ -71,11 +75,20 @@ class ReleasePlugin extends PluginHelper implements Plugin<Project> {
project.task('runBuildTasks', group: RELEASE_GROUP, description: 'Runs the build process in a separate gradle run.', type: GradleBuild) {
startParameter = project.getGradle().startParameter.newInstance()

// name tasks with an absolute path so subprojects can be released independently
String p = project.getPath()
p = !p.endsWith(Project.PATH_SEPARATOR) ? p + Project.PATH_SEPARATOR : p;

ArrayList<String> buildTasks = new ArrayList<>();
extension.buildTasks.each { String task ->
buildTasks.add(p + task);
}

project.afterEvaluate {
tasks = [
'beforeReleaseBuild',
extension.buildTasks,
'afterReleaseBuild'
"${p}beforeReleaseBuild" as String,
buildTasks,
"${p}afterReleaseBuild" as String
].flatten()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ class GitReleasePluginIntegrationTests extends GitSpecification {
localGit.push().setForce(true).call()
when: 'calling release task indirectly'
project.tasks['release'].tasks.each { task ->
if (task == "runBuildTasks") {
project.tasks[task].tasks.each { buildTask ->
project.tasks[buildTask].execute()
if (task == ":runBuildTasks") {
project.tasks.getByPath(task).tasks.each { buildTask ->
project.tasks.getByPath(buildTask).execute()
}
} else {
project.tasks[task].execute()
project.tasks.getByPath(task).execute()
}
}
def st = localGit.status().call()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,13 @@ class ReleasePluginTests extends Specification {
project.version == '1.2'

}

def 'subproject tasks are named with qualified paths'() {
given:
Project sub = ProjectBuilder.builder().withName('sub').withParent(project).withProjectDir(testDir).build()
sub.apply plugin: ReleasePlugin

expect:
sub.tasks.release.tasks.every { it.startsWith(':sub:') }
}
}

0 comments on commit 86980c4

Please sign in to comment.