1
- buildscript {
2
- repositories { mavenCentral() }
3
- dependencies { classpath " com.github.spullara.mustache.java:compiler:${ VER_MUSTACHE} " }
4
- }
5
1
plugins {
6
- id ' cz.malohlava.visteg' version ' 1.0.5' // https://github.com/mmalohlava/gradle-visteg
2
+ // https://www.benediktritter.de/maven-plugin-development/#release-history
3
+ id ' de.benediktritter.maven-plugin-development' version ' 0.4.0'
7
4
}
5
+
8
6
repositories { mavenCentral() }
9
7
apply from : rootProject. file(' gradle/changelog.gradle' )
10
- apply from : rootProject. file(' gradle/spotless-freshmark.gradle' )
11
-
12
- // to generate taskGraph.pdf
13
- // - set enabled (below) to true
14
- // - run: ./gradlew :plugin-maven:test
15
- // - run: rm plugin-maven/output.pdf
16
- // - run: dot -Tpdf plugin-maven/build/reports/visteg.dot > plugin-maven/taskGraph.pdf
17
- visteg {
18
- enabled = false
19
- nodeShape = ' box'
20
- startNodeShape = ' box'
21
- endNodeShape = ' box'
22
- colorscheme = ' pastel24' // https://www.graphviz.org/doc/info/colors.html
23
- }
24
-
25
- import com.github.mustachejava.DefaultMustacheFactory
26
-
27
- import java.nio.file.Files
28
-
29
- import static java.nio.charset.StandardCharsets.UTF_8
30
- import static java.nio.file.StandardOpenOption.CREATE
31
- import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING
32
-
33
8
ext. artifactId = project. artifactIdMaven
34
9
version = spotlessChangelog. versionNext
35
- apply from : rootProject. file(" gradle/java-setup.gradle" )
36
- apply from : rootProject. file(" gradle/java-publish.gradle" )
37
10
38
- final MAVEN_PROJECT_DIR = project . layout . buildDirectory . dir( " mavenProject " ) . get( )
39
- final LOCAL_MAVEN_REPO_DIR = project . layout . buildDirectory . dir( " localMavenRepository " ) . get( )
11
+ apply from : rootProject . file( " gradle/java-setup.gradle " )
12
+ apply from : rootProject . file( ' gradle/spotless-freshmark.gradle ' )
40
13
41
14
def mvnw (String args ) {
42
15
boolean isWin = System . getProperty(' os.name' ). toLowerCase(). contains(' win' )
@@ -55,17 +28,15 @@ def mvnw(String args) {
55
28
}
56
29
}
57
30
58
- String libVersion = version. endsWith(' -SNAPSHOT' ) ?
59
- rootProject. spotlessChangelog. versionNext :
60
- rootProject. spotlessChangelog. versionLast
31
+ apply plugin : ' de.benediktritter.maven-plugin-development'
32
+ mavenPlugin {
33
+ name = ' Spotless Maven Plugin'
34
+ artifactId = project. artifactIdMaven
35
+ description = project. description
36
+ }
61
37
dependencies {
62
- if (version. endsWith(' -SNAPSHOT' ) || (rootProject. spotlessChangelog. versionNext == rootProject. spotlessChangelog. versionLast)) {
63
- implementation project(' :lib' )
64
- implementation project(' :lib-extra' )
65
- } else {
66
- implementation " com.diffplug.spotless:spotless-lib:${ libVersion} "
67
- implementation " com.diffplug.spotless:spotless-lib-extra:${ libVersion} "
68
- }
38
+ implementation project(' :lib' )
39
+ implementation project(' :lib-extra' )
69
40
70
41
compileOnly " org.apache.maven:maven-plugin-api:${ VER_MAVEN_API} "
71
42
compileOnly " org.apache.maven.plugin-tools:maven-plugin-annotations:${ VER_MAVEN_API} "
@@ -90,112 +61,14 @@ dependencies {
90
61
testImplementation " org.apache.maven:maven-core:${ VER_MAVEN_API} "
91
62
}
92
63
93
- task copySourceFiles (type : Sync ) {
94
- from " src/main/java"
95
- into MAVEN_PROJECT_DIR . dir(" src/main/java" )
96
- }
97
-
98
- task copyMvnw (type : Copy , dependsOn : copySourceFiles) {
99
- from ' src/test/resources'
100
- include ' mvnw'
101
- include ' mvnw.cmd'
102
- include ' .mvn/**'
103
- into MAVEN_PROJECT_DIR
104
- }
105
-
106
- task installLocalDependencies
107
- def libs = [
108
- ' lib' ,
109
- ' lib-extra' ,
110
- ' testlib'
111
- ]
112
- libs. each {
113
- def groupId = ' com.diffplug.spotless'
114
- def artifactId = " spotless-${ it} "
115
- def jarTask = tasks. getByPath(" :${ it} :jar" )
116
- def file = jarTask. archivePath
117
-
118
- def installDependency = task " install_${ artifactId} " (type : Exec ) {
119
- workingDir MAVEN_PROJECT_DIR
120
-
121
- inputs. file(file)
122
- outputs. dir(LOCAL_MAVEN_REPO_DIR . file(groupId. replace(' .' , ' /' ) + " /" + artifactId + " /" + version))
123
- commandLine mvnw(" org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file " +
124
- " -Dfile=${ file} " +
125
- " -DgroupId=${ groupId} " +
126
- " -DartifactId=${ artifactId} " +
127
- " -Dversion=${ libVersion} " +
128
- " -Dpackaging=jar " +
129
- " -DlocalRepositoryPath=${ LOCAL_MAVEN_REPO_DIR} " )
130
- }
131
- installDependency. dependsOn(jarTask)
132
-
133
- installLocalDependencies. dependsOn installDependency
134
- }
135
-
136
- task createPomXml (dependsOn : installLocalDependencies) {
137
- def newPomXml = MAVEN_PROJECT_DIR . file(" pom.xml" ). asFile. toPath()
138
-
139
- outputs. file(newPomXml)
140
- doLast {
141
- def additionalDependencies = project. configurations. runtimeClasspath. resolvedConfiguration. resolvedArtifacts. findAll {
142
- return ! libs. contains(it. moduleVersion. id. name)
143
- }. collect {
144
- return " <dependency>\n " +
145
- " <groupId>${ it.moduleVersion.id.group} </groupId>\n " +
146
- " <artifactId>${ it.moduleVersion.id.name} </artifactId>\n " +
147
- " <version>${ it.moduleVersion.id.version} </version>\n " +
148
- " </dependency>\n "
149
- }. join()
150
-
151
- def versions = [
152
- spotlessMavenPluginVersion : version,
153
- mavenApiVersion : VER_MAVEN_API ,
154
- eclipseAetherVersion : VER_ECLIPSE_AETHER ,
155
- spotlessLibVersion : libVersion,
156
- jsr305Version : VER_JSR_305 ,
157
- additionalDependencies : additionalDependencies
158
- ]
159
-
160
- def pomXmlTemplate = project. layout. projectDirectory. file(" src/test/resources/pom-build.xml.mustache" ). asFile. toPath()
161
-
162
- Files . newBufferedReader(pomXmlTemplate). withCloseable { reader ->
163
- Files . newBufferedWriter(newPomXml, UTF_8 , CREATE , TRUNCATE_EXISTING ). withCloseable { writer ->
164
- def mustache = new DefaultMustacheFactory (). compile(reader, " pom" )
165
- mustache. execute(writer, versions)
166
- }
167
- }
168
- }
169
- }
170
-
171
- task runMavenBuild (type : Exec , dependsOn : [
172
- copySourceFiles,
173
- copyMvnw,
174
- createPomXml
175
- ]) {
176
- outputs. dir(LOCAL_MAVEN_REPO_DIR )
177
-
178
- workingDir MAVEN_PROJECT_DIR
179
- // -B batch mode to make dependency download logging less verbose
180
- commandLine mvnw(" clean install -B -Dmaven.repo.local=${ LOCAL_MAVEN_REPO_DIR} " )
181
- }
182
-
183
- jar. setActions Arrays . asList()
184
- jar. dependsOn(runMavenBuild)
185
- File jarIn = MAVEN_PROJECT_DIR . file(" target/spotless-maven-plugin-${ version} .jar" ). asFile
186
- File jarOut = jar. archivePath
187
- jar. inputs. file(jarIn)
188
- jar. outputs. file(jarOut)
189
- jar. doLast {
190
- Files . copy(jarIn. toPath(), jarOut. toPath(), java.nio.file.StandardCopyOption . REPLACE_EXISTING )
191
- }
192
-
193
- test { useJUnitPlatform() }
194
-
195
64
apply from : rootProject. file(' gradle/special-tests.gradle' )
196
65
197
- tasks. withType(Test ) {
198
- systemProperty " localMavenRepositoryDir" , LOCAL_MAVEN_REPO_DIR . asFile
199
- systemProperty " spotlessMavenPluginVersion" , project. version
200
- dependsOn(jar)
66
+ tasks. withType(Test ). configureEach {
67
+ useJUnitPlatform()
68
+ systemProperty ' spotlessMavenPluginVersion' , project. version
69
+ dependsOn ' publishToMavenLocal'
70
+ dependsOn ' :lib:publishToMavenLocal'
71
+ dependsOn ' :lib-extra:publishToMavenLocal'
201
72
}
73
+
74
+ apply from : rootProject. file(" gradle/java-publish.gradle" )
0 commit comments