Refactor RootProjectPlugin to organize build logic in private methods describing the function applied to the build.
This commit is contained in:
@@ -38,33 +38,11 @@ class RootProjectPlugin implements Plugin<Project> {
|
|||||||
void apply(Project project) {
|
void apply(Project project) {
|
||||||
|
|
||||||
applyPlugins(project)
|
applyPlugins(project)
|
||||||
|
configureMavenCentralRepository(project)
|
||||||
project.allprojects {
|
configureResolutionStrategy(project)
|
||||||
configurations.all {
|
|
||||||
resolutionStrategy {
|
|
||||||
cacheChangingModulesFor 0, 'seconds'
|
|
||||||
cacheDynamicVersionsFor 0, 'seconds'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adds the Maven Central Repository to the list of repositories used by this build to resolve dependencies.
|
|
||||||
project.repositories.mavenCentral()
|
|
||||||
|
|
||||||
configureSonarQube(project)
|
configureSonarQube(project)
|
||||||
|
createDependencyManagementExportTask(project)
|
||||||
project.tasks.create("dependencyManagementExport", DependencyManagementExportTask)
|
createReleasePublishedArtifactsTask(project)
|
||||||
|
|
||||||
project.task("releasePublishedArtifacts", { Task releasePublishedArtifacts ->
|
|
||||||
if (isReleasingToMavenCentral(project)) {
|
|
||||||
releasePublishedArtifacts.dependsOn project.tasks.closeAndReleaseOssrhStagingRepository
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("all")
|
|
||||||
private boolean isReleasingToMavenCentral(Project project) {
|
|
||||||
Utils.isRelease(project) && project.hasProperty("ossrhUsername")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
@@ -79,6 +57,30 @@ class RootProjectPlugin implements Plugin<Project> {
|
|||||||
pluginManager.apply("org.sonarqube")
|
pluginManager.apply("org.sonarqube")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the Maven Central Repository to the list of repositories used by this Gradle {@link Project} build
|
||||||
|
* to resolve dependencies.
|
||||||
|
*
|
||||||
|
* @param project Gradle {@link Project}.
|
||||||
|
* @see org.gradle.api.Project
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
private void configureMavenCentralRepository(Project project) {
|
||||||
|
project.repositories.mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
private void configureResolutionStrategy(Project project) {
|
||||||
|
|
||||||
|
project.allprojects {
|
||||||
|
configurations.all {
|
||||||
|
resolutionStrategy {
|
||||||
|
cacheChangingModulesFor 0, 'seconds'
|
||||||
|
cacheDynamicVersionsFor 0, 'seconds'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void configureSonarQube(Project project) {
|
private void configureSonarQube(Project project) {
|
||||||
|
|
||||||
String projectName = Utils.getProjectName(project)
|
String projectName = Utils.getProjectName(project)
|
||||||
@@ -96,4 +98,23 @@ class RootProjectPlugin implements Plugin<Project> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
private void createDependencyManagementExportTask(Project project) {
|
||||||
|
project.tasks.create("dependencyManagementExport", DependencyManagementExportTask)
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createReleasePublishedArtifactsTask(Project project) {
|
||||||
|
|
||||||
|
project.task("releasePublishedArtifacts", { Task releasePublishedArtifacts ->
|
||||||
|
if (isReleasingToMavenCentral(project)) {
|
||||||
|
releasePublishedArtifacts.dependsOn project.tasks.closeAndReleaseOssrhStagingRepository
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
private boolean isReleasingToMavenCentral(Project project) {
|
||||||
|
Utils.isRelease(project) && project.hasProperty("ossrhUsername")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user