Repository navigation
Expand file tree
/
Copy pathbuild.gradle
More file actions
271 lines (248 loc) · 10.6 KB
/
Copy pathbuild.gradle
File metadata and controls
271 lines (248 loc) · 10.6 KB
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
plugins {
id 'java'
id 'maven-publish'
id 'java-gradle-plugin'
id 'com.gradle.plugin-publish' version '1.3.1'
id 'eclipse'
id 'de.undercouch.download' version '5.7.0'
id 'signing'
}
repositories {
mavenLocal()
mavenCentral()
maven {
url = uri('https://plugins.gradle.org/m2/')
}
}
gradlePlugin {
website = 'http://github.com/javapackager/JavaPackager'
vcsUrl = 'http://github.com/javapackager/JavaPackager.git'
description = 'Packages Java applications as native Windows, MacOS or GNU/Linux executables and creates installers for them'
plugins {
create("javaPackagerPlugin") {
id = 'io.github.javapackager'
displayName = 'JavaPackager'
implementationClass = 'io.github.javapackager.gradle.PackagePlugin'
tags.set(['java', 'packager', 'gradle-plugin', 'maven-plugin', 'native', 'installer', 'debian-packages', 'rpm-packages', 'dmg', 'maven', 'gradle', 'distribution', 'javapackager', 'linux-executables', 'deb', 'rpm', 'native-windows', 'java-applications', 'pkg', 'msi'])
}
}
}
// maven-plugin-plugin generates the Maven plugin descriptor (see generatePluginDescriptor)
def mavenPluginPluginVersion = '3.16.0'
configurations {
mavenEmbedder
}
dependencies {
implementation 'org.apache.maven:maven-plugin-api:3.6.0'
implementation 'org.apache.maven:maven-core:3.6.0'
// jdeb requires plexus-utils 4, which moved Xpp3Dom to plexus-xml (3.x is the Maven 3 compatible line)
implementation 'org.codehaus.plexus:plexus-utils:4.1.0'
implementation 'org.codehaus.plexus:plexus-xml:3.1.0'
implementation 'org.twdata.maven:mojo-executor:2.4.1'
implementation 'commons-io:commons-io:2.22.0'
implementation 'org.apache.commons:commons-lang3:3.21.0'
implementation 'org.apache.commons:commons-collections4:4.6.0'
implementation 'org.apache.commons:commons-compress:1.28.0'
implementation 'org.apache.velocity:velocity-engine-core:2.4.1'
implementation 'org.vafer:jdeb:1.14'
implementation 'net.jsign:jsign-core:6.0'
implementation 'org.redline-rpm:redline:1.2.10'
implementation 'edu.sc.seis.launch4j:launch4j:4.0.0'
compileOnly 'org.apache.maven.plugin-tools:maven-plugin-annotations:3.16.0'
compileOnly 'javax.inject:javax.inject:1' // provided by Maven at runtime
mavenEmbedder 'org.apache.maven:maven-embedder:3.9.16'
mavenEmbedder 'org.apache.maven:maven-compat:3.9.16'
mavenEmbedder 'org.slf4j:slf4j-simple:1.7.36'
mavenEmbedder 'org.apache.maven.resolver:maven-resolver-connector-basic:1.9.27'
mavenEmbedder 'org.apache.maven.resolver:maven-resolver-transport-wagon:1.9.27'
mavenEmbedder 'org.apache.maven.wagon:wagon-http:3.5.3'
mavenEmbedder 'org.apache.maven.wagon:wagon-provider-api:3.5.3'
}
group = 'io.github.javapackager'
version = '2.0.0'
description = 'Hybrid Maven/Gradle plugin to package Java applications as native Windows, Mac OS X or GNU/Linux executables and create installers for them'
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
compileJava.options.encoding = 'UTF-8'
// Java 8 target is deliberate: don't warn that it's obsolete on newer JDKs
compileJava.options.compilerArgs << '-Xlint:-options'
// suppress javadoc warnings
javadoc.options.addStringOption('Xdoclint:none', '-quiet')
java {
withSourcesJar()
withJavadocJar()
}
// Maven Central publication (Central Portal)
publishing {
repositories {
maven {
// credentials are a Central Portal user token; releases use the Portal OSSRH Staging API
// and must be uploaded to the Portal afterwards (see releaseToCentral)
def releasesRepoUrl = "https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"
def snapshotsRepoUrl = "https://central.sonatype.com/repository/maven-snapshots/"
name = "MavenCentral"
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
credentials {
username = project.findProperty("ossrhUsername") ?: ''
password = project.findProperty("ossrhPassword") ?: ''
}
}
}
publications {
pluginMaven(MavenPublication) {
def directory = buildDir.canonicalPath
def outputDirectory = compileJava.destinationDirectory.asFile.get().canonicalPath
pom.withXml {
asNode().appendNode('build')
.with {
appendNode('directory', directory)
appendNode('outputDirectory', outputDirectory)
// keeps the 'javapackager:' goal prefix (maven-plugin-plugin can't compute it from the artifactId)
appendNode('plugins').appendNode('plugin').with {
appendNode('groupId', 'org.apache.maven.plugins')
appendNode('artifactId', 'maven-plugin-plugin')
appendNode('version', mavenPluginPluginVersion)
appendNode('configuration').appendNode('goalPrefix', 'javapackager')
}
}
// Maven provides its own API to plugins: maven-plugin-api and maven-core must be 'provided' and
// mojo-executor and jdeb (also Maven plugins) must not bring other Maven versions.
// The launch4j Gradle library is only used by the Gradle plugin and only published on the
// Gradle Plugin Portal, so it's left out of the POM: Maven users only need Maven Central (#444).
// (Gradle consumers use the .module file, so they are not affected)
def dependencies = asNode().dependencies[0]
dependencies.dependency.findAll { it.groupId.text() == 'edu.sc.seis.launch4j' }.each { dependencies.remove(it) }
dependencies.dependency.each { dep ->
def artifactId = dep.artifactId.text()
if (artifactId in ['maven-plugin-api', 'maven-core']) {
dep.scope[0].value = 'provided'
} else if (artifactId in ['mojo-executor', 'jdeb']) {
dep.appendNode('exclusions').appendNode('exclusion').with {
appendNode('groupId', 'org.apache.maven')
appendNode('artifactId', '*')
}
}
}
}
pom {
name = project.name
groupId = project.group
artifactId = project.name
packaging = 'maven-plugin'
}
}
}
afterEvaluate {
publications {
withType(MavenPublication) {
// customize all publications here
pom {
version = project.version
description = project.description
url = 'https://github.com/javapackager/JavaPackager'
scm {
connection = 'scm:git:git://github.com/javapackager/JavaPackager.git'
developerConnection = 'scm:git:git@github.com:javapackager/JavaPackager.git'
url = 'https://github.com/javapackager/JavaPackager'
}
licenses {
license {
name = 'GPL-v3.0'
url = 'http://www.gnu.org/licenses/gpl-3.0.txt'
distribution = 'repo'
}
}
developers {
developer {
id = 'fvarrui'
name = 'Francisco Vargas Ruiz'
url = 'https://github.com/fvarrui'
}
}
}
}
}
}
}
// runs the plugin description generator
tasks.register('generatePluginDescriptor', JavaExec) {
dependsOn compileJava
def pluginDescriptorFile = new File(project.compileJava.destinationDirectory.asFile.get(), 'META-INF/maven/plugin.xml')
// FIXME: this does not seem to be working
inputs.files project.compileJava.outputs.files
outputs.file pluginDescriptorFile
classpath = configurations.mavenEmbedder
mainClass = 'org.apache.maven.cli.MavenCli'
systemProperties['maven.multiModuleProjectDirectory'] = projectDir
args = [
'--errors',
'--batch-mode',
'--file', generatePomFileForPluginMavenPublication.destination,
"org.apache.maven.plugins:maven-plugin-plugin:${mavenPluginPluginVersion}:descriptor",
'-Dproject.build.sourceEncoding=' + compileJava.options.encoding
]
doLast {
assert pluginDescriptorFile.file, "${pluginDescriptorFile.canonicalPath}: was not generated"
logger.info("Plugin descriptor is generated in ${pluginDescriptorFile.canonicalPath}")
}
}
generatePluginDescriptor.dependsOn(generatePomFileForPluginMavenPublication)
project.classes.dependsOn(generatePluginDescriptor)
project.validatePlugins.dependsOn(generatePluginDescriptor)
publishToMavenLocal.dependsOn(build)
// Signature of publication
signing {
setRequired {
// signing is only required if release artifacts are to be published (snapshots aren't validated)
!version.endsWith('SNAPSHOT') && gradle.taskGraph.allTasks.any { it instanceof PublishToMavenRepository }
}
// all publications (plugin and Gradle plugin marker): Maven Central rejects unsigned release artifacts
sign publishing.publications
}
// Publishes a release and uploads it to the Central Portal, where it waits to be published manually
// (https://central.sonatype.com/publishing/deployments). Snapshots only need 'publish'.
tasks.register('releaseToCentral') {
group 'publishing'
description 'Publishes the release to the Central Portal (OSSRH Staging API) and uploads it for manual publishing.'
dependsOn 'publish'
doLast {
if (version.endsWith('SNAPSHOT')) {
throw new GradleException("releaseToCentral is for releases; use 'publish' for ${version}")
}
def token = "${project.findProperty('ossrhUsername') ?: ''}:${project.findProperty('ossrhPassword') ?: ''}".bytes.encodeBase64().toString()
def url = new URL("https://ossrh-staging-api.central.sonatype.com/manual/upload/defaultRepository/${project.group}?publishing_type=user_managed")
def connection = (HttpURLConnection) url.openConnection()
connection.requestMethod = 'POST'
connection.setRequestProperty('Authorization', "Bearer ${token}")
def status = connection.responseCode
def response = (status < 400 ? connection.inputStream : connection.errorStream)?.text
if (status >= 400) {
throw new GradleException("Central Portal upload failed (HTTP ${status}): ${response}")
}
logger.lifecycle("Uploaded to the Central Portal (HTTP ${status}). Review and publish it at https://central.sonatype.com/publishing/deployments")
}
}
tasks.register('updateNativeJavaApplicationStub', Download) {
def version = '20251202.010109'
group 'Update assets'
description 'Downloads the native macOS launchers (nativeJavaApplicationStub) to src/main/resources/mac and overwrites the existing ones.'
src([
"https://github.com/javapackager/nativeJavaApplicationStub/releases/download/${version}/nativeJavaApplicationStub",
"https://github.com/javapackager/nativeJavaApplicationStub/releases/download/${version}/nativeJavaApplicationStub.arm64",
"https://github.com/javapackager/nativeJavaApplicationStub/releases/download/${version}/nativeJavaApplicationStub.x86_64"
])
dest file('src/main/resources/mac')
overwrite true
}
tasks.register('updateWhyJavaLauncher', Download) {
def version = '1.1.2'
group 'Update assets'
description 'Downloads JavaLauncher.exe to src/main/resources/windows and overwrites the existing one.'
src([
"https://github.com/AstroImageJ/Why/releases/download/${version}/JavaLauncher.exe"
])
dest file('src/main/resources/windows')
overwrite true
}