diff --git a/laa-ccms-java-gradle-plugin/src/main/groovy/uk/gov/laa/ccms/gradle/LaaCcmsJavaGradlePlugin.groovy b/laa-ccms-java-gradle-plugin/src/main/groovy/uk/gov/laa/ccms/gradle/LaaCcmsJavaGradlePlugin.groovy index 6ad6dd0..8dd3748 100644 --- a/laa-ccms-java-gradle-plugin/src/main/groovy/uk/gov/laa/ccms/gradle/LaaCcmsJavaGradlePlugin.groovy +++ b/laa-ccms-java-gradle-plugin/src/main/groovy/uk/gov/laa/ccms/gradle/LaaCcmsJavaGradlePlugin.groovy @@ -5,6 +5,8 @@ import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.plugins.JavaPlugin import org.gradle.api.plugins.quality.CheckstylePlugin +import org.gradle.api.publish.maven.plugins.MavenPublishPlugin +import org.gradle.api.publish.maven.tasks.AbstractPublishToMaven import org.gradle.api.tasks.testing.Test import org.gradle.jvm.toolchain.JavaLanguageVersion import org.gradle.testing.jacoco.plugins.JacocoPlugin @@ -21,6 +23,7 @@ class LaaCcmsJavaGradlePlugin implements Plugin { target.pluginManager.apply JacocoPlugin target.pluginManager.apply VersionsPlugin target.pluginManager.apply CheckstylePlugin + target.pluginManager.apply MavenPublishPlugin target.java { toolchain.languageVersion.set(JavaLanguageVersion.of(JAVA_VERSION)) @@ -71,7 +74,7 @@ class LaaCcmsJavaGradlePlugin implements Plugin { showViolations = true } - target.tasks.withType(AbstractPublishToMaven) { + target.tasks.withType(AbstractPublishToMaven).configureEach { doLast { logger.lifecycle("Published Maven artifact: " + "${publication.groupId}:${publication.artifactId}:${publication.version}") @@ -79,8 +82,8 @@ class LaaCcmsJavaGradlePlugin implements Plugin { } //used for deploying snapshot packages - target.task("updateSnapshotVersion") - .doLast(task -> { + target.tasks.register("updateSnapshotVersion") { + doLast(task -> { def gitHash = "git rev-parse --short HEAD".execute().text.trim() def propertiesFile = file('gradle.properties') def properties = new Properties() @@ -89,9 +92,9 @@ class LaaCcmsJavaGradlePlugin implements Plugin { def currentVersion = properties.getProperty('version') def newVersion = currentVersion.replace('-SNAPSHOT', "-${gitHash}-SNAPSHOT") properties.setProperty('version', newVersion) - properties.store(propertiesFile.newWriter(), null) } ) + } } }