@@ -24,21 +24,18 @@ visteg {
2424import com.github.mustachejava.DefaultMustacheFactory
2525
2626import java.nio.file.Files
27- import java.nio.file.Paths
2827
2928import static java.nio.charset.StandardCharsets.UTF_8
30- import static java.nio.file.StandardOpenOption.CREATE_NEW
29+ import static java.nio.file.StandardOpenOption.CREATE
3130import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING
3231
3332ext. artifactId = project. artifactIdMaven
3433version = spotlessChangelog. versionNext
3534apply from : rootProject. file(" gradle/java-setup.gradle" )
3635apply from : rootProject. file(" gradle/java-publish.gradle" )
3736
38- final PROJECT_DIR = project. projectDir. toString()
39- final BUILD_DIR = project. buildDir. toString()
40- final MAVEN_PROJECT_DIR = " ${ BUILD_DIR} /mavenProject"
41- final LOCAL_MAVEN_REPO_DIR = " ${ BUILD_DIR} /localMavenRepository"
37+ final MAVEN_PROJECT_DIR = project. layout. buildDirectory. dir(" mavenProject" ). get()
38+ final LOCAL_MAVEN_REPO_DIR = project. layout. buildDirectory. dir(" localMavenRepository" ). get()
4239
4340def mvnw (String args ) {
4441 boolean isWin = System . getProperty(' os.name' ). toLowerCase(). contains(' win' )
@@ -91,11 +88,9 @@ dependencies {
9188 testImplementation " org.apache.maven:maven-core:${ VER_MAVEN_API} "
9289}
9390
94- task cleanMavenProjectDir (type : Delete ) { delete MAVEN_PROJECT_DIR }
95-
96- task copySourceFiles (type : Sync , dependsOn : cleanMavenProjectDir) {
91+ task copySourceFiles (type : Sync ) {
9792 from " src/main/java"
98- into " ${ MAVEN_PROJECT_DIR} / src/main/java"
93+ into MAVEN_PROJECT_DIR . dir( " src/main/java" )
9994}
10095
10196task copyMvnw (type : Copy , dependsOn : copySourceFiles) {
@@ -122,7 +117,7 @@ libs.each {
122117 workingDir MAVEN_PROJECT_DIR
123118
124119 inputs. file(file)
125- outputs. dir(project . file(" ${ LOCAL_MAVEN_REPO_DIR } / ${ groupId.replace('.', '/')} / ${ artifactId} / ${ version } " ))
120+ outputs. dir(LOCAL_MAVEN_REPO_DIR . file(groupId. replace(' .' , ' /' ) + " / " + artifactId + " / " + version ))
126121 commandLine mvnw(" org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file " +
127122 " -Dfile=${ file} " +
128123 " -DgroupId=${ groupId} " +
@@ -137,6 +132,9 @@ libs.each {
137132}
138133
139134task createPomXml (dependsOn : installLocalDependencies) {
135+ def newPomXml = MAVEN_PROJECT_DIR . file(" pom.xml" ). asFile. toPath()
136+
137+ outputs. file(newPomXml)
140138 doLast {
141139 def additionalDependencies = project. configurations. runtimeClasspath. resolvedConfiguration. resolvedArtifacts. findAll {
142140 return ! libs. contains(it. moduleVersion. id. name)
@@ -157,11 +155,10 @@ task createPomXml(dependsOn: installLocalDependencies) {
157155 additionalDependencies : additionalDependencies
158156 ]
159157
160- def pomXmlTemplate = Paths . get(PROJECT_DIR , " src/test/resources/pom-build.xml.mustache" )
161- def newPomXml = Paths . get(MAVEN_PROJECT_DIR , " pom.xml" )
158+ def pomXmlTemplate = project. layout. projectDirectory. file(" src/test/resources/pom-build.xml.mustache" ). asFile. toPath()
162159
163160 Files . newBufferedReader(pomXmlTemplate). withCloseable { reader ->
164- Files . newBufferedWriter(newPomXml, UTF_8 , CREATE_NEW , TRUNCATE_EXISTING ). withCloseable { writer ->
161+ Files . newBufferedWriter(newPomXml, UTF_8 , CREATE , TRUNCATE_EXISTING ). withCloseable { writer ->
165162 def mustache = new DefaultMustacheFactory (). compile(reader, " pom" )
166163 mustache. execute(writer, versions)
167164 }
@@ -170,19 +167,20 @@ task createPomXml(dependsOn: installLocalDependencies) {
170167}
171168
172169task runMavenBuild (type : Exec , dependsOn : [
173- cleanMavenProjectDir,
174170 copySourceFiles,
175171 copyMvnw,
176172 createPomXml
177173]) {
174+ outputs. dir(LOCAL_MAVEN_REPO_DIR )
175+
178176 workingDir MAVEN_PROJECT_DIR
179177 // -B batch mode to make dependency download logging less verbose
180178 commandLine mvnw(" clean install -B -Dmaven.repo.local=${ LOCAL_MAVEN_REPO_DIR} " )
181179}
182180
183181jar. setActions Arrays . asList()
184182jar. dependsOn(runMavenBuild)
185- File jarIn = file(" ${ MAVEN_PROJECT_DIR } / target/spotless-maven-plugin-${ version} .jar" )
183+ File jarIn = MAVEN_PROJECT_DIR . file(" target/spotless-maven-plugin-${ version} .jar" ). asFile
186184File jarOut = jar. archivePath
187185jar. inputs. file(jarIn)
188186jar. outputs. file(jarOut)
@@ -195,7 +193,7 @@ test { useJUnitPlatform() }
195193apply from : rootProject. file(' gradle/special-tests.gradle' )
196194
197195tasks. withType(Test ) {
198- systemProperty " localMavenRepositoryDir" , LOCAL_MAVEN_REPO_DIR
196+ systemProperty " localMavenRepositoryDir" , LOCAL_MAVEN_REPO_DIR . asFile
199197 systemProperty " spotlessMavenPluginVersion" , project. version
200198 dependsOn(jar)
201199}
0 commit comments