-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle
231 lines (198 loc) · 7.27 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
buildscript {
ext {
mavenVersion = "$mavenVersionCore"
}
}
plugins {
id 'java'
id 'maven'
id 'signing'
id 'maven-publish'
id 'io.github.gradle-nexus.publish-plugin' version '1.0.0'
}
// parameterization
def defGroupId = 'com.appland'
def defArtifactId = 'appmap-maven-plugin'
def defName = 'AppMap Maven Plugin'
def defVersion = "1.3.0"
def defDescription = 'Maven plugin to record AppMaps with the appmap.jar agent'
def defGitSlug = "applandinc/appmap-java-maven-plugin"
def defMavenRepo = 'https://s01.oss.sonatype.org'
def paramSignKey = findProperty('signingKey')
def paramSignPassword = findProperty("signingPassword")
def paramRepoUsername = findProperty('ossrhUsername')
def paramRepoPassword = findProperty('ossrhPassword')
def paramDescription = findProperty('artifactDescription') ?: defDescription
def paramName = findProperty('artifactName') ?: defName
def paramGroupId = findProperty('publicationGroupId') ?: defGroupId
def paramArtifactId = findProperty('publicationArtifactId') ?: defArtifactId
def paramGitSlug = System.getenv("TRAVIS_REPO_SLUG") ?: defGitSlug
def paramMavenRepo = findProperty('mavenRepo') ?: defMavenRepo
def paramVersion = findProperty('paramVersion')
def travisVersion = System.getenv("TRAVIS_BRANCH")
def versionLikeRegexp = /^\d+\.\d+.*/
def travisVersionOK = travisVersion && (travisVersion ==~ versionLikeRegexp)
paramVersion = paramVersion ?: (travisVersionOK ? travisVersion : defVersion)
if (findProperty('snapshot') != null) {
paramVersion += '-SNAPSHOT'
}
println "version:$paramVersion"
// required by NexusPublishing
version = paramVersion
group = paramGroupId
repositories {
mavenCentral()
}
configurations {
mavenEmbedder
}
dependencies {
compileOnly 'org.apache.maven.plugin-tools:maven-plugin-annotations:3.6.0'
implementation 'org.apache.commons:commons-text:1.9'
implementation 'org.apache.maven:maven-plugin-api:3.6.1'
implementation 'org.apache.maven:maven-core:3.5.4'
implementation 'com.appland:appmap-agent:[1.3, 2.0)'
testImplementation 'junit:junit:4.13.1'
// as per https://stackoverflow.com/a/64726155
mavenEmbedder 'org.apache.maven:maven-embedder:3.6.3'
mavenEmbedder 'org.apache.maven:maven-compat:3.6.3'
mavenEmbedder 'org.apache.maven.resolver:maven-resolver-connector-basic:1.4.1'
mavenEmbedder 'org.apache.maven.resolver:maven-resolver-transport-http:1.4.1'
mavenEmbedder 'org.slf4j:slf4j-simple:1.7.30'
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
compileJava.options.encoding = 'UTF-8'
install.repositories.mavenInstaller.pom.with {
groupId = paramGroupId
artifactId = paramArtifactId
version = paramVersion
packaging = 'maven-plugin'
name = paramName
description = paramDescription
}
// runs the plugin description generator
task generatePluginDescriptor(type: JavaExec, dependsOn: compileJava) {
def pomFile = file("$buildDir/pom.xml")
def pluginDescriptorFile = new File(project.compileJava.destinationDir, 'META-INF/maven/plugin.xml')
def directory = buildDir.canonicalPath
def outputDirectory = compileJava.destinationDir.canonicalPath
// FIXME: this does not seem to be working
inputs.files project.compileJava.outputs.files
outputs.file pluginDescriptorFile
classpath = configurations.mavenEmbedder
main = 'org.apache.maven.cli.MavenCli'
systemProperties['maven.multiModuleProjectDirectory'] = projectDir
args = [
'--quiet',
'--errors',
'--batch-mode',
'--file', "${buildDir}/pom.xml",
'org.apache.maven.plugins:maven-plugin-plugin:3.6.0:descriptor',
'-Dproject.build.sourceEncoding=' + compileJava.options.encoding
]
doFirst {
// we have to do it in this cryptic way, instead of
// ```
// project {
// build {
// directory = directory
// outputDirectory = outputDirectory
// }
// }
// because MavenModel already defines build and so it will
// result in No such property: _SCRIPT_CLASS_NAME_ for class: org.apache.maven.model.Model
install.repositories
.mavenInstaller
.pom
.withXml {
asNode().appendNode('build')
.with {
appendNode('directory', directory)
appendNode('outputDirectory', outputDirectory)
}
}
.writeTo(pomFile)
assert pomFile.file, "${pomFile.canonicalPath}: was not generated"
logger.info("POM is generated in ${pomFile.canonicalPath}")
}
doLast {
assert pluginDescriptorFile.file, "${pluginDescriptorFile.canonicalPath}: was not generated"
logger.info("Plugin descriptor is generated in ${pluginDescriptorFile.canonicalPath}")
}
}
project.jar.dependsOn(generatePluginDescriptor)
// demand generation of extra artifacts
apply plugin: 'java'
java {
withSourcesJar()
withJavadocJar()
}
/* TODO: Test is not passing
test {
useJUnitPlatform()
}
*/
// declare publications and repositories
apply plugin: 'maven-publish'
publishing {
publications {
appMapPlugin(MavenPublication) {
// requirements: https://central.sonatype.org/pages/requirements.html
// 1. coordinates
groupId paramGroupId
artifactId paramArtifactId
version paramVersion
// 2. artifacts
from components.java
//// the artifacts below added automatically by `java { with... }` block above
// artifact sourcesJar
// artifact javadocJar
// metadata
// TBD: parameterize more values?
pom {
name = paramName // "$paramGroupId:$paramArtifactId"
description = paramDescription
url = "https://appland.com"
licenses {
license {
name = "MIT"
url = "https://raw.githubusercontent.com/$paramGitSlug/master/LICENSE.txt"
}
}
developers {
developer {
// id = "kgilpin"
name = "Kevin Gilpin"
email = "[email protected]"
organization = "AppLand Inc."
url = "https://dev.to/kgilpin"
}
}
scm {
connection = "scm:git:git://github.com/${paramGitSlug}.git"
developerConnection = "scm:git:ssh://github.com:${paramGitSlug}.git"
url = "https://github.com/${paramGitSlug}/tree/master"
}
}
}
}
}
nexusPublishing {
repositories {
sonatype {
nexusUrl = uri(paramMavenRepo + "/service/local/")
snapshotRepositoryUrl = uri(paramMavenRepo + "/content/repositories/snapshots")
username = paramRepoUsername
password = paramRepoPassword
}
}
}
// conditionally inject sign tasks into the flow
if (paramSignKey) {
apply plugin: 'signing'
signing {
useInMemoryPgpKeys(paramSignKey, paramSignPassword)
sign publishing.publications.appMapPlugin
}
}