forked from diffplug/spotless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
206 lines (178 loc) · 6.79 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
buildscript {
repositories { mavenCentral() }
dependencies { classpath "com.github.spullara.mustache.java:compiler:${VER_MUSTACHE}" }
}
plugins {
id 'cz.malohlava.visteg' version '1.0.5' // https://github.com/mmalohlava/gradle-visteg
}
apply from: rootProject.file('gradle/changelog.gradle')
apply from: rootProject.file('gradle/spotless-freshmark.gradle')
// to generate taskGraph.pdf
// - set enabled (below) to true
// - run: ./gradlew :plugin-maven:test
// - run: rm plugin-maven/output.pdf
// - run: dot -Tpdf plugin-maven/build/reports/visteg.dot > plugin-maven/taskGraph.pdf
visteg {
enabled = false
nodeShape = 'box'
startNodeShape = 'box'
endNodeShape = 'box'
colorscheme = 'pastel24' // https://www.graphviz.org/doc/info/colors.html
}
import com.github.mustachejava.DefaultMustacheFactory
import java.nio.file.Files
import java.nio.file.Paths
import static java.nio.charset.StandardCharsets.UTF_8
import static java.nio.file.StandardOpenOption.CREATE_NEW
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING
ext.artifactId = project.artifactIdMaven
version = spotlessChangelog.versionNext
apply from: rootProject.file("gradle/java-setup.gradle")
apply from: rootProject.file("gradle/java-publish.gradle")
final PROJECT_DIR = project.projectDir.toString()
final BUILD_DIR = project.buildDir.toString()
final MAVEN_PROJECT_DIR = "${BUILD_DIR}/mavenProject"
final LOCAL_MAVEN_REPO_DIR = "${BUILD_DIR}/localMavenRepository"
def mvnw(String args) {
boolean isWin = System.getProperty('os.name').toLowerCase().contains('win')
if (isWin) {
return [
'cmd',
'/c',
'mvnw.cmd -e ' + args
]
} else {
return [
'/bin/sh',
'-c',
'./mvnw -e ' + args
]
}
}
String libVersion = version.endsWith('-SNAPSHOT') ?
rootProject.spotlessChangelog.versionNext :
rootProject.spotlessChangelog.versionLast
dependencies {
if (version.endsWith('-SNAPSHOT') || (rootProject.spotlessChangelog.versionNext == rootProject.spotlessChangelog.versionLast)) {
implementation project(':lib')
implementation project(':lib-extra')
} else {
implementation "com.diffplug.spotless:spotless-lib:${libVersion}"
implementation "com.diffplug.spotless:spotless-lib-extra:${libVersion}"
}
implementation "org.codehaus.plexus:plexus-resources:${VER_PLEXUS_RESOURCES}"
constraints {
implementation("org.codehaus.plexus:plexus-utils:3.4.1") {
because("version pulled by plexus-resources has a functional-bug affecting " +
"directory scanning times")
}
}
compileOnly "org.apache.maven:maven-plugin-api:${VER_MAVEN_API}"
compileOnly "org.apache.maven.plugin-tools:maven-plugin-annotations:${VER_MAVEN_API}"
compileOnly "org.eclipse.aether:aether-api:${VER_ECLIPSE_AETHER}"
compileOnly "org.eclipse.aether:aether-util:${VER_ECLIPSE_AETHER}"
implementation "com.diffplug.durian:durian-core:${VER_DURIAN}"
implementation "com.diffplug.durian:durian-collect:${VER_DURIAN}"
implementation "org.eclipse.jgit:org.eclipse.jgit:${VER_JGIT}"
testImplementation project(":testlib")
testImplementation "org.junit.jupiter:junit-jupiter:${VER_JUNIT}"
testImplementation "org.assertj:assertj-core:${VER_ASSERTJ}"
testImplementation "org.mockito:mockito-core:${VER_MOCKITO}"
testImplementation "com.diffplug.durian:durian-io:${VER_DURIAN}"
testImplementation "com.github.spullara.mustache.java:compiler:${VER_MUSTACHE}"
testImplementation "org.apache.maven:maven-plugin-api:${VER_MAVEN_API}"
testImplementation "org.eclipse.aether:aether-api:${VER_ECLIPSE_AETHER}"
testImplementation "org.codehaus.plexus:plexus-resources:${VER_PLEXUS_RESOURCES}"
}
task cleanMavenProjectDir(type: Delete) { delete MAVEN_PROJECT_DIR }
task copySourceFiles(type: Sync, dependsOn: cleanMavenProjectDir) {
from "src/main/java"
into "${MAVEN_PROJECT_DIR}/src/main/java"
}
task copyMvnw(type: Copy, dependsOn: copySourceFiles) {
from 'src/test/resources'
include 'mvnw'
include 'mvnw.cmd'
include '.mvn/**'
into MAVEN_PROJECT_DIR
}
task installLocalDependencies
def libs = [
'lib',
'lib-extra',
'testlib'
]
libs.each {
def groupId = 'com.diffplug.spotless'
def artifactId = "spotless-${it}"
def jarTask = tasks.getByPath(":${it}:jar")
def file = jarTask.archivePath
def installDependency = task "install_${artifactId}"(type: Exec) {
workingDir MAVEN_PROJECT_DIR
inputs.file(file)
outputs.dir(project.file("${LOCAL_MAVEN_REPO_DIR}/${groupId.replace('.', '/')}/${artifactId}/${version}"))
commandLine mvnw("org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file " +
"-Dfile=${file} " +
"-DgroupId=${groupId} " +
"-DartifactId=${artifactId} " +
"-Dversion=${libVersion} " +
"-Dpackaging=jar " +
"-DlocalRepositoryPath=${LOCAL_MAVEN_REPO_DIR}")
}
installDependency.dependsOn(jarTask)
installLocalDependencies.dependsOn installDependency
}
task createPomXml(dependsOn: installLocalDependencies) {
doLast {
def additionalDependencies = project.configurations.runtimeClasspath.resolvedConfiguration.resolvedArtifacts.findAll {
return !libs.contains(it.moduleVersion.id.name)
}.collect {
return " <dependency>\n" +
" <groupId>${it.moduleVersion.id.group}</groupId>\n" +
" <artifactId>${it.moduleVersion.id.name}</artifactId>\n" +
" <version>${it.moduleVersion.id.version}</version>\n" +
" </dependency>\n"
}.join()
def versions = [
spotlessMavenPluginVersion: version,
mavenApiVersion : VER_MAVEN_API,
eclipseAetherVersion : VER_ECLIPSE_AETHER,
spotlessLibVersion : libVersion,
additionalDependencies : additionalDependencies
]
def pomXmlTemplate = Paths.get(PROJECT_DIR, "src/test/resources/pom-build.xml.mustache")
def newPomXml = Paths.get(MAVEN_PROJECT_DIR, "pom.xml")
Files.newBufferedReader(pomXmlTemplate).withCloseable { reader ->
Files.newBufferedWriter(newPomXml, UTF_8, CREATE_NEW, TRUNCATE_EXISTING).withCloseable { writer ->
def mustache = new DefaultMustacheFactory().compile(reader, "pom")
mustache.execute(writer, versions)
}
}
}
}
task runMavenBuild(type: Exec, dependsOn: [
cleanMavenProjectDir,
copySourceFiles,
copyMvnw,
createPomXml
]) {
workingDir MAVEN_PROJECT_DIR
// -B batch mode to make dependency download logging less verbose
commandLine mvnw("clean install -B -Dmaven.repo.local=${LOCAL_MAVEN_REPO_DIR}")
}
jar.setActions Arrays.asList()
jar.dependsOn(runMavenBuild)
File jarIn = file("${MAVEN_PROJECT_DIR}/target/spotless-maven-plugin-${version}.jar")
File jarOut = jar.archivePath
jar.inputs.file(jarIn)
jar.outputs.file(jarOut)
jar.doLast {
Files.copy(jarIn.toPath(), jarOut.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING)
}
test { useJUnitPlatform() }
apply from: rootProject.file('gradle/special-tests.gradle')
tasks.withType(Test) {
systemProperty "localMavenRepositoryDir", LOCAL_MAVEN_REPO_DIR
systemProperty "spotlessMavenPluginVersion", project.version
dependsOn(jar)
}