Skip to content

Commit 9940d74

Browse files
committed
Use project.layout instead of buildDir and static strings
1 parent e19c3ad commit 9940d74

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

gradle/java-setup.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ tasks.named('spotbugsTest') {
2626
}
2727

2828
tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach {
29-
outputs.file("$buildDir/reports/spotbugs/${it.name}.html")
30-
outputs.file("$buildDir/spotbugs/auxclasspath/${it.name}")
29+
outputs.file(project.layout.buildDirectory.file("reports/spotbugs/${it.name}.html"))
30+
outputs.file(project.layout.buildDirectory.file("spotbugs/auxclasspath/${it.name}"))
3131
reports {
3232
html.enabled = true
3333
}

plugin-maven/build.gradle

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ visteg {
2424
import com.github.mustachejava.DefaultMustacheFactory
2525

2626
import java.nio.file.Files
27-
import java.nio.file.Paths
2827

2928
import static java.nio.charset.StandardCharsets.UTF_8
3029
import static java.nio.file.StandardOpenOption.CREATE
@@ -35,10 +34,8 @@ version = spotlessChangelog.versionNext
3534
apply from: rootProject.file("gradle/java-setup.gradle")
3635
apply 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

4340
def mvnw(String args) {
4441
boolean isWin = System.getProperty('os.name').toLowerCase().contains('win')
@@ -93,7 +90,7 @@ dependencies {
9390

9491
task copySourceFiles(type: Sync) {
9592
from "src/main/java"
96-
into "${MAVEN_PROJECT_DIR}/src/main/java"
93+
into MAVEN_PROJECT_DIR.dir("src/main/java")
9794
}
9895

9996
task copyMvnw(type: Copy, dependsOn: copySourceFiles) {
@@ -120,7 +117,7 @@ libs.each {
120117
workingDir MAVEN_PROJECT_DIR
121118

122119
inputs.file(file)
123-
outputs.dir(project.file("${LOCAL_MAVEN_REPO_DIR}/${groupId.replace('.', '/')}/${artifactId}/${version}"))
120+
outputs.dir(LOCAL_MAVEN_REPO_DIR.file(groupId.replace('.', '/') + "/" + artifactId + "/" + version))
124121
commandLine mvnw("org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file " +
125122
"-Dfile=${file} " +
126123
"-DgroupId=${groupId} " +
@@ -135,7 +132,7 @@ libs.each {
135132
}
136133

137134
task createPomXml(dependsOn: installLocalDependencies) {
138-
def newPomXml = Paths.get(MAVEN_PROJECT_DIR, "pom.xml")
135+
def newPomXml = MAVEN_PROJECT_DIR.file("pom.xml").asFile.toPath()
139136

140137
outputs.file(newPomXml)
141138
doLast {
@@ -158,7 +155,7 @@ task createPomXml(dependsOn: installLocalDependencies) {
158155
additionalDependencies : additionalDependencies
159156
]
160157

161-
def pomXmlTemplate = Paths.get(PROJECT_DIR, "src/test/resources/pom-build.xml.mustache")
158+
def pomXmlTemplate = project.layout.projectDirectory.file("src/test/resources/pom-build.xml.mustache").asFile.toPath()
162159

163160
Files.newBufferedReader(pomXmlTemplate).withCloseable { reader ->
164161
Files.newBufferedWriter(newPomXml, UTF_8, CREATE, TRUNCATE_EXISTING).withCloseable { writer ->
@@ -183,7 +180,7 @@ task runMavenBuild(type: Exec, dependsOn: [
183180

184181
jar.setActions Arrays.asList()
185182
jar.dependsOn(runMavenBuild)
186-
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
187184
File jarOut = jar.archivePath
188185
jar.inputs.file(jarIn)
189186
jar.outputs.file(jarOut)
@@ -196,7 +193,7 @@ test { useJUnitPlatform() }
196193
apply from: rootProject.file('gradle/special-tests.gradle')
197194

198195
tasks.withType(Test) {
199-
systemProperty "localMavenRepositoryDir", LOCAL_MAVEN_REPO_DIR
196+
systemProperty "localMavenRepositoryDir", LOCAL_MAVEN_REPO_DIR.asFile
200197
systemProperty "spotlessMavenPluginVersion", project.version
201198
dependsOn(jar)
202199
}

0 commit comments

Comments
 (0)