@@ -24,21 +24,18 @@ visteg {
24
24
import com.github.mustachejava.DefaultMustacheFactory
25
25
26
26
import java.nio.file.Files
27
- import java.nio.file.Paths
28
27
29
28
import static java.nio.charset.StandardCharsets.UTF_8
30
- import static java.nio.file.StandardOpenOption.CREATE_NEW
29
+ import static java.nio.file.StandardOpenOption.CREATE
31
30
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING
32
31
33
32
ext. artifactId = project. artifactIdMaven
34
33
version = spotlessChangelog. versionNext
35
34
apply from : rootProject. file(" gradle/java-setup.gradle" )
36
35
apply from : rootProject. file(" gradle/java-publish.gradle" )
37
36
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()
42
39
43
40
def mvnw (String args ) {
44
41
boolean isWin = System . getProperty(' os.name' ). toLowerCase(). contains(' win' )
@@ -91,11 +88,9 @@ dependencies {
91
88
testImplementation " org.apache.maven:maven-core:${ VER_MAVEN_API} "
92
89
}
93
90
94
- task cleanMavenProjectDir (type : Delete ) { delete MAVEN_PROJECT_DIR }
95
-
96
- task copySourceFiles (type : Sync , dependsOn : cleanMavenProjectDir) {
91
+ task copySourceFiles (type : Sync ) {
97
92
from " src/main/java"
98
- into " ${ MAVEN_PROJECT_DIR} / src/main/java"
93
+ into MAVEN_PROJECT_DIR . dir( " src/main/java" )
99
94
}
100
95
101
96
task copyMvnw (type : Copy , dependsOn : copySourceFiles) {
@@ -122,7 +117,7 @@ libs.each {
122
117
workingDir MAVEN_PROJECT_DIR
123
118
124
119
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 ))
126
121
commandLine mvnw(" org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file " +
127
122
" -Dfile=${ file} " +
128
123
" -DgroupId=${ groupId} " +
@@ -137,6 +132,9 @@ libs.each {
137
132
}
138
133
139
134
task createPomXml (dependsOn : installLocalDependencies) {
135
+ def newPomXml = MAVEN_PROJECT_DIR . file(" pom.xml" ). asFile. toPath()
136
+
137
+ outputs. file(newPomXml)
140
138
doLast {
141
139
def additionalDependencies = project. configurations. runtimeClasspath. resolvedConfiguration. resolvedArtifacts. findAll {
142
140
return ! libs. contains(it. moduleVersion. id. name)
@@ -157,11 +155,10 @@ task createPomXml(dependsOn: installLocalDependencies) {
157
155
additionalDependencies : additionalDependencies
158
156
]
159
157
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()
162
159
163
160
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 ->
165
162
def mustache = new DefaultMustacheFactory (). compile(reader, " pom" )
166
163
mustache. execute(writer, versions)
167
164
}
@@ -170,19 +167,20 @@ task createPomXml(dependsOn: installLocalDependencies) {
170
167
}
171
168
172
169
task runMavenBuild (type : Exec , dependsOn : [
173
- cleanMavenProjectDir,
174
170
copySourceFiles,
175
171
copyMvnw,
176
172
createPomXml
177
173
]) {
174
+ outputs. dir(LOCAL_MAVEN_REPO_DIR )
175
+
178
176
workingDir MAVEN_PROJECT_DIR
179
177
// -B batch mode to make dependency download logging less verbose
180
178
commandLine mvnw(" clean install -B -Dmaven.repo.local=${ LOCAL_MAVEN_REPO_DIR} " )
181
179
}
182
180
183
181
jar. setActions Arrays . asList()
184
182
jar. 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
186
184
File jarOut = jar. archivePath
187
185
jar. inputs. file(jarIn)
188
186
jar. outputs. file(jarOut)
@@ -195,7 +193,7 @@ test { useJUnitPlatform() }
195
193
apply from : rootProject. file(' gradle/special-tests.gradle' )
196
194
197
195
tasks. withType(Test ) {
198
- systemProperty " localMavenRepositoryDir" , LOCAL_MAVEN_REPO_DIR
196
+ systemProperty " localMavenRepositoryDir" , LOCAL_MAVEN_REPO_DIR . asFile
199
197
systemProperty " spotlessMavenPluginVersion" , project. version
200
198
dependsOn(jar)
201
199
}
0 commit comments