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
- def mvnw (String args ) {
42
- boolean isWin = System . getProperty(' os.name' ). toLowerCase(). contains(' win' )
43
- if (isWin) {
44
- return [
45
- ' cmd' ,
46
- ' /c' ,
47
- ' mvnw.cmd -e ' + args
48
- ]
49
- } else {
50
- return [
51
- ' /bin/sh' ,
52
- ' -c' ,
53
- ' ./mvnw -e ' + args
54
- ]
55
- }
14
+ apply plugin : ' de.benediktritter.maven-plugin-development'
15
+ mavenPlugin {
16
+ name = ' Spotless Maven Plugin'
17
+ artifactId = project. artifactIdMaven
18
+ description = project. description
56
19
}
57
20
58
- String libVersion = version . endsWith( ' -SNAPSHOT ' ) ?
59
- rootProject . spotlessChangelog . versionNext :
60
- rootProject . spotlessChangelog . versionLast
21
+ String VER_MAVEN_API = ' 3.0 '
22
+ String VER_ECLIPSE_AETHER = ' 1.1.0 '
23
+ String VER_PLEXUS_RESOURCES = ' 1.2.0 '
61
24
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
- }
25
+ implementation project(' :lib' )
26
+ implementation project(' :lib-extra' )
69
27
70
28
compileOnly " org.apache.maven:maven-plugin-api:${ VER_MAVEN_API} "
71
29
compileOnly " org.apache.maven.plugin-tools:maven-plugin-annotations:${ VER_MAVEN_API} "
@@ -83,119 +41,19 @@ dependencies {
83
41
testImplementation " org.assertj:assertj-core:${ VER_ASSERTJ} "
84
42
testImplementation " org.mockito:mockito-core:${ VER_MOCKITO} "
85
43
testImplementation " com.diffplug.durian:durian-io:${ VER_DURIAN} "
86
- testImplementation " com.github.spullara.mustache.java:compiler:${ VER_MUSTACHE } "
44
+ testImplementation ' com.github.spullara.mustache.java:compiler:0.9.10 '
87
45
testImplementation " org.apache.maven:maven-plugin-api:${ VER_MAVEN_API} "
88
46
testImplementation " org.eclipse.aether:aether-api:${ VER_ECLIPSE_AETHER} "
89
47
testImplementation " org.codehaus.plexus:plexus-resources:${ VER_PLEXUS_RESOURCES} "
90
48
testImplementation " org.apache.maven:maven-core:${ VER_MAVEN_API} "
91
49
}
92
50
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
51
apply from : rootProject. file(' gradle/special-tests.gradle' )
196
-
197
- tasks . withType( Test ) {
198
- systemProperty " localMavenRepositoryDir " , LOCAL_MAVEN_REPO_DIR . asFile
199
- systemProperty " spotlessMavenPluginVersion " , project . version
200
- dependsOn(jar)
52
+ tasks . withType( Test ) . configureEach {
53
+ systemProperty ' spotlessMavenPluginVersion ' , project . version
54
+ dependsOn ' publishToMavenLocal '
55
+ dependsOn ' :lib:publishToMavenLocal '
56
+ dependsOn ' :lib-extra:publishToMavenLocal '
201
57
}
58
+
59
+ apply from : rootProject. file(" gradle/java-publish.gradle" )
0 commit comments