-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathbuild.gradle
More file actions
325 lines (283 loc) · 12.1 KB
/
build.gradle
File metadata and controls
325 lines (283 loc) · 12.1 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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
plugins {
id "com.gradle.plugin-publish" version "1.3.1"
id 'signing' // Required for Maven Central
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0' // Automates Sonatype Nexus publishing
}
apply plugin: 'java'
apply plugin: 'maven-publish'
apply from: "${buildscript.sourceFile.parentFile}/scripts/VersionNumber.gradle"
apply from: "${buildscript.sourceFile.parentFile}/scripts/javapreprocessor.gradle"
group = 'de.inetsoftware'
def LIB_GRADLE_VERSION = System.getenv('LIB_GRADLE_VERSION') ?: '8.1.0' // Gradle version for the wrapper
wrapper.gradleVersion = LIB_GRADLE_VERSION
def gVersion = VersionNumber.parse( gradle.gradleVersion )
println 'Gradle version: ' + gVersion
// Load version from gradle.properties file directly
def propertiesFile = file("${project.projectDir}/gradle.properties")
def versionProperty = '8.4.23'
def isSnapshot = false
if (propertiesFile.exists()) {
def props = new Properties()
propertiesFile.withInputStream { props.load(it) }
versionProperty = props.getProperty('version', '8.4.23')
}
def baseVersionFromProps = versionProperty.split('-')[0] // Remove -SNAPSHOT if present
isSnapshot = versionProperty.contains('-SNAPSHOT')
// Fetch version mapping script to validate/adjust version based on Gradle version
apply from: "${buildscript.sourceFile.parentFile}/scripts/SetupBuilderVersion.gradle"
def expectedBaseVersion = setupBuilderVersion('0').split('\\.')[0..1].join('.') // Get major.minor (e.g., "8.4")
def actualBaseVersion = baseVersionFromProps.split('\\.')[0..1].join('.') // Get major.minor from properties
// Extract build number (patch version) from gradle.properties version
def buildNumber = baseVersionFromProps.split('\\.')[2] ?: '0'
// Validate version compatibility with Gradle version
if (actualBaseVersion != expectedBaseVersion) {
println "WARNING: Version in gradle.properties (${actualBaseVersion}) doesn't match expected version for Gradle ${gradle.gradleVersion} (${expectedBaseVersion})"
println "Adjusting version to match Gradle compatibility..."
version = "${expectedBaseVersion}.${buildNumber}" + (isSnapshot ? '-SNAPSHOT' : '')
} else {
version = versionProperty
}
def baseVersion = "${actualBaseVersion}.${buildNumber}"
println 'SetupBuilder version: ' + version
java.sourceCompatibility = 1.8
compileJava.options.encoding = 'UTF-8'
repositories {
mavenCentral()
}
dependencies {
api gradleApi()
// Test dependencies
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.hamcrest:hamcrest-core:2.2'
}
sourceSets {
main {
java {
srcDirs = ['src']
srcDirs = ["${buildDir}/preparedSrc-${gVersion}"]
exclude '**/test/**' // Exclude test files from main source set
}
resources {
srcDirs = ['src']
exclude '**/*.java'
exclude '**/package.html'
exclude '**/test/**' // Exclude test files from resources
}
}
test {
java {
srcDirs = ['src/test']
}
}
}
/* Configure JPP - exclude test files */
JPP.setJPPSources( "src", [
"gradleVersion" : "${gVersion}",
"outputDirectory" : "${buildDir}/preparedSrc-${gVersion}"
]);
// Configure publishing
// - Snapshots: Published to Sonatype snapshot repository
// - Releases: Published to Sonatype staging repository (then closed and released)
// - Local development: Use `./gradlew publishToMavenLocal` to publish to mavenLocal()
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
pom {
name = 'Gradle Setup Builder Plugin'
description = 'The Setup Builder is a plugin for Gradle which can create native setups for different platforms like Windows, Linux and OSX.'
url = 'https://github.com/i-net-software/SetupBuilder'
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'inetsoftware'
name = 'i-net software'
}
}
scm {
connection = 'scm:git:git://github.com/i-net-software/SetupBuilder.git'
developerConnection = 'scm:git:ssh://github.com/i-net-software/SetupBuilder.git'
url = 'https://github.com/i-net-software/SetupBuilder'
}
}
}
}
// For local development, use mavenLocal()
repositories {
mavenLocal()
}
}
println "Publishing version: ${version}"
println "Note: For local development, use './gradlew publishToMavenLocal'"
println " For snapshots, use './gradlew publishToSonatype' (requires Sonatype credentials)"
println " Snapshots are available at: https://oss.sonatype.org/content/repositories/snapshots/"
// Configure Nexus Publish Plugin for Sonatype/Maven Central
// Configure for both snapshots and releases
// Snapshots go to: https://oss.sonatype.org/content/repositories/snapshots/
// Releases go to staging, then are closed and released to Maven Central
nexusPublishing {
repositories {
sonatype {
// New Central Portal URLs
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
// Credentials - try both property name variations
username.set(
project.findProperty('ossrhUsername')
?: project.findProperty('sonatypeUsername')
?: System.getenv('SONATYPE_USERNAME')
?: System.getenv('OSSRH_USERNAME')
?: ""
)
password.set(
project.findProperty('ossrhPassword')
?: project.findProperty('sonatypePassword')
?: System.getenv('SONATYPE_PASSWORD')
?: System.getenv('OSSRH_PASSWORD')
?: ""
)
// Staging profile ID - should be the UUID from Sonatype, not the domain
// Get it from: https://central.sonatype.com/ -> Staging Profiles
// Or leave it out to auto-detect by groupId
// If you have a staging profile UUID, uncomment and set it:
// stagingProfileId.set('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')
}
}
// Configure closeStagingRepositories task (only for releases, not snapshots)
closeStagingRepositories {
closeStagingRepositories.dependsOn 'publishToSonatype'
// Only close staging for releases (non-snapshot versions)
onlyIf { !version.toString().endsWith('-SNAPSHOT') }
}
// For snapshots, just publish (don't close staging)
// For releases, close and release staging repositories
if (!version.toString().endsWith('-SNAPSHOT')) {
publish.finalizedBy 'closeStagingRepositories'
}
}
// Configure signing for Maven Central
// Sign both snapshots and releases when credentials are available
// Note: Signing is only required for Maven Central, not for mavenLocal()
def hasSigningKey = (System.getenv('SIGNING_KEY') != null || project.findProperty('signing.key') != null)
def isPublishingToMavenLocal = gradle.startParameter.taskNames.any {
it.contains('MavenLocal') || it.contains('mavenLocal')
}
if (!isPublishingToMavenLocal && hasSigningKey) {
// Only sign when publishing to Sonatype and signing key is available
signing {
required { true }
useInMemoryPgpKeys(
System.getenv('SIGNING_KEY') ?: project.findProperty('signing.key'),
System.getenv('SIGNING_PASSWORD') ?: project.findProperty('signing.password')
)
sign publishing.publications.mavenJava
}
} else {
// Skip signing for mavenLocal
signing {
required { false }
}
}
javadoc {
// Third party libs
exclude "**/image4j"
exclude "**/icns"
}
gradlePlugin {
website = 'https://github.com/i-net-software/SetupBuilder'
vcsUrl = 'https://github.com/i-net-software/SetupBuilder'
plugins {
setupBuilderPlugin {
id = 'de.inetsoftware.setupbuilder'
implementationClass = 'com.inet.gradle.setup.SetupBuilderPlugin'
displayName = 'Gradle Setup Builder plugin'
description = 'The Setup Builder is a plugin for Gradle which can create native setups for different platforms like Windows, Linux and OSX. The output is a *.msi, a *.deb, a *.rpm or a *.dmg file.'
tags.set( ['setup', 'installer', 'msi', 'dmg', 'deb', 'rpm', 'windows', 'linux', 'osx' ] )
}
appBundlerPlugin {
id = 'de.inetsoftware.appbundler'
implementationClass = 'com.inet.gradle.appbundler.AppBundlerPlugin'
description = 'Create a Java bundled application for OSX'
displayName = 'Gradle Application Bundler plugin for OSX'
tags.set( ['app'] )
}
}
}
// see https://discuss.gradle.org/t/add-apikey-and-apisecret-to-pluginbundle-extension-for-plugin-publish-plugin/8636/3
task setupPluginUpload {
publishPlugins.dependsOn 'setupPluginUpload'
doLast {
def key=System.env.gradlePublishKey
def secret = System.env.gradlePublishSecret
if( !key || !secret)
{
throw new RuntimeException("gradlePublishKey and/or gradlePublishSecret are not defined environment variables")
}
System.properties.setProperty("gradle.publish.key", key)
System.properties.setProperty("gradle.publish.secret", secret)
}
}
// Check for the current operating system to load the specific build task
import org.apache.tools.ant.taskdefs.condition.Os
def dependingTask = 'deb'
if (Os.isFamily(Os.FAMILY_MAC)) {
dependingTask = 'dmg'
} else if (Os.isFamily(Os.FAMILY_WINDOWS)) {
dependingTask = 'msi'
}
// run the following task as a dependency to the "check"-task.
task runSetupBuilderTestTasks(type: GradleBuild) {
check.dependsOn runSetupBuilderTestTasks
dir = file('testBuilds')
tasks = ['clean', dependingTask]
// Only run if test or check tasks are explicitly requested (not as dependencies)
// AND not in CI environment (testBuilds has environment-specific requirements:
// - macOS: needs Java 8 for DMG builds
// - Windows: needs Java in specific path for MSI builds
// - Linux: needs deb/rpm build tools)
onlyIf {
def requestedTasks = project.gradle.startParameter.taskNames
def isRequested = requestedTasks.contains('test') || requestedTasks.contains('check')
// Detect CI environment (GitHub Actions, Jenkins, Travis, etc.)
// GitHub Actions sets CI=true and GITHUB_ACTIONS=true
def isCI = System.getenv('CI') != null ||
System.getenv('GITHUB_ACTIONS') != null ||
System.getenv('JENKINS_URL') != null ||
System.getenv('TRAVIS') != null
return isRequested && !isCI
}
}
afterEvaluate {
// The first one ususally wins.
project.tasks.withType( Copy ).all {
println "Setting Duplication Strategy in afterEvaluate: ${it}"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
// The first one ususally wins.
project.tasks.withType( Jar ).all {
println "Setting Duplication Strategy in afterEvaluate: ${it}"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
}
// hack the Eclipse .classpath file
apply plugin: 'eclipse'
eclipse {
classpath {
file {
whenMerged { classpath ->
// Entferne Ressourcen-Einträge, die falsch gesetzt wurden
classpath.entries.removeAll { entry ->
if ( entry.kind == 'src' ) {
entry.excludes = []
entry.path.contains( 'preparedSrc' )
}
}
}
}
}
}