Skip to content

Commit 7c57d32

Browse files
committed
Speed up Gradle 9 builds
1 parent e356496 commit 7c57d32

File tree

10 files changed

+322
-239
lines changed

10 files changed

+322
-239
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ jobs:
138138
uses: gradle/actions/wrapper-validation@v5.0.2
139139
- name: Test with Gradle Wrapper
140140
run: |
141-
./gradlew :jme3-screenshot-test:screenshotTest
141+
./gradlew :jme3-screenshot-tests:screenshotTest
142142
- name: Upload Test Reports
143143
uses: actions/upload-artifact@v7.0.0
144144
if: always()
@@ -285,8 +285,7 @@ jobs:
285285
shell: bash
286286
run: |
287287
# Normal build plus ZIP distribution and merged javadoc
288-
./gradlew -PuseCommitHashAsVersionName=true -PskipPrebuildLibraries=true \
289-
-x checkstyleMain -x checkstyleTest \
288+
./gradlew -PuseCommitHashAsVersionName=true -PskipPrebuildLibraries=true -PbuildJavaDoc=true \
290289
build createZipDistribution mergedJavadoc
291290
292291
if [ "${{ matrix.deploy }}" = "true" ];
@@ -306,13 +305,13 @@ jobs:
306305
echo "SIGNING_KEY, SIGNING_PASSWORD"
307306
308307
./gradlew publishMavenPublicationToDistRepository \
309-
-PskipPrebuildLibraries=true -PuseCommitHashAsVersionName=true \
308+
-PskipPrebuildLibraries=true -PuseCommitHashAsVersionName=true -PbuildJavaDoc=true \
310309
--console=plain --stacktrace
311310
else
312311
./gradlew publishMavenPublicationToDistRepository \
313312
-PsigningKey='${{ secrets.SIGNING_KEY }}' \
314313
-PsigningPassword='${{ secrets.SIGNING_PASSWORD }}' \
315-
-PskipPrebuildLibraries=true -PuseCommitHashAsVersionName=true \
314+
-PskipPrebuildLibraries=true -PuseCommitHashAsVersionName=true -PbuildJavaDoc=true \
316315
--console=plain --stacktrace
317316
fi
318317
@@ -491,6 +490,7 @@ jobs:
491490
-PsigningKey='${{ secrets.SIGNING_KEY }}' \
492491
-PsigningPassword='${{ secrets.SIGNING_PASSWORD }}' \
493492
-PuseCommitHashAsVersionName=true \
493+
-PbuildJavaDoc=true \
494494
--console=plain --stacktrace
495495
fi
496496
@@ -554,6 +554,7 @@ jobs:
554554
-PsigningKey='${{ secrets.SIGNING_KEY }}' \
555555
-PsigningPassword='${{ secrets.SIGNING_PASSWORD }}' \
556556
-PuseCommitHashAsVersionName=true \
557+
-PbuildJavaDoc=true \
557558
--console=plain --stacktrace
558559
.github/actions/tools/uploadToCentral.sh \
559560
-p '${{ secrets.CENTRAL_PASSWORD }}' \

CONTRIBUTING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,14 @@ Run the Gradle wrapper:
139139

140140
After a successful build,
141141
snapshot jars will be found in the "*/build/libs" subfolders.
142+
The default build skips JavaDoc and source archives for speed; release and
143+
publishing tasks build them explicitly.
142144

143145
### Related Gradle tasks
144146

145147
You can install the Maven artifacts to your local repository:
146-
+ using Bash or PowerShell: `./gradlew install`
147-
+ using Windows Command Prompt: `.\gradlew install`
148+
+ using Bash or PowerShell: `./gradlew -PbuildJavaDoc=true install`
149+
+ using Windows Command Prompt: `.\gradlew -PbuildJavaDoc=true install`
148150

149151
You can restore the project to a pristine state:
150152
+ using Bash or PowerShell: `./gradlew clean`

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@ Read our [contribution guide](https://github.com/jMonkeyEngine/jmonkeyengine/blo
9797

9898
After a successful build,
9999
fresh JARs will be found in "*/build/libs".
100+
The default build skips JavaDoc and source archives for speed; release and
101+
publishing tasks build them explicitly.
100102

101103
You can install the JARs to your local Maven repository:
102-
+ using Bash or Fish or PowerShell or Zsh: `./gradlew install`
103-
+ using Windows Command Prompt: `.\gradlew install`
104+
+ using Bash or Fish or PowerShell or Zsh: `./gradlew -PbuildJavaDoc=true install`
105+
+ using Windows Command Prompt: `.\gradlew -PbuildJavaDoc=true install`
104106

105107
You can run the "jme3-examples" app:
106108
+ using Bash or Fish or PowerShell or Zsh: `./gradlew run`

build.gradle

Lines changed: 70 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ buildscript {
1313
}
1414

1515
import org.gradle.api.file.RelativePath
16+
import java.nio.file.Files
17+
import java.nio.file.StandardCopyOption
1618

1719
// Set the license for IDEs that understand this
1820
ext.license = file("$rootDir/source-file-header-template.txt")
@@ -25,7 +27,7 @@ allprojects {
2527
mavenCentral()
2628
google()
2729
}
28-
tasks.withType(Jar) {
30+
tasks.withType(Jar).configureEach {
2931
duplicatesStrategy = 'include'
3032
}
3133
}
@@ -47,7 +49,7 @@ subprojects {
4749
toolVersion = libs.versions.spotbugs.get()
4850
}
4951

50-
tasks.withType(com.github.spotbugs.snom.SpotBugsTask ) {
52+
tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach {
5153
reports {
5254
html.required = !project.hasProperty("xml-reports")
5355
xml.required = project.hasProperty("xml-reports")
@@ -63,39 +65,57 @@ tasks.register('run') {
6365

6466
defaultTasks 'run'
6567

68+
def fileSystemOperations = services.get(FileSystemOperations)
69+
def libDistDir = layout.buildDirectory.dir('libDist')
70+
def libDistArchives = subprojects.collectMany { subproject ->
71+
if (subproject.hasProperty('mainClassName')) {
72+
return []
73+
}
74+
subproject.tasks.withType(Jar).matching { task ->
75+
task.name == 'jar' ||
76+
task.name == 'sourcesJar' ||
77+
(buildJavaDoc == "true" && task.name == 'javadocJar')
78+
}.collect { archiveTask ->
79+
[
80+
projectName: subproject.name,
81+
archiveFile: archiveTask.archiveFile,
82+
archiveClassifier: archiveTask.archiveClassifier,
83+
archiveExtension: archiveTask.archiveExtension,
84+
]
85+
}
86+
}
87+
6688
def libDist = tasks.register('libDist') {
67-
dependsOn(subprojects.collect { it.tasks.named('build') })
89+
dependsOn(libDistArchives.collect { it.archiveFile })
6890
description = 'Builds and copies the engine binaries, sources and javadoc to build/libDist'
91+
inputs.files(libDistArchives.collect { it.archiveFile })
92+
outputs.dir(libDistDir)
6993

7094
doLast {
71-
File libFolder = mkdir("$buildDir/libDist/lib")
72-
File sourceFolder = mkdir("$buildDir/libDist/sources")
73-
File javadocFolder = mkdir("$buildDir/libDist/javadoc")
74-
subprojects.each {project ->
75-
if(!project.hasProperty('mainClassName')){
76-
project.tasks.withType(Jar).each {archiveTask ->
77-
String classifier = archiveTask.archiveClassifier.get()
78-
String ext = archiveTask.archiveExtension.get()
79-
File archiveFile = archiveTask.archiveFile.get().asFile
80-
if (classifier == "sources") {
81-
copy {
82-
from archiveFile
83-
into sourceFolder
84-
rename {project.name + '-' + classifier + '.' + ext}
85-
}
86-
} else if (classifier == "javadoc") {
87-
copy {
88-
from archiveFile
89-
into javadocFolder
90-
rename {project.name + '-' + classifier + '.' + ext}
91-
}
92-
} else{
93-
copy {
94-
from archiveFile
95-
into libFolder
96-
rename {project.name + '.' + ext}
97-
}
98-
}
95+
File libFolder = libDistDir.get().dir('lib').asFile
96+
File sourceFolder = libDistDir.get().dir('sources').asFile
97+
File javadocFolder = libDistDir.get().dir('javadoc').asFile
98+
libDistArchives.each { archive ->
99+
String classifier = archive.archiveClassifier.get()
100+
String ext = archive.archiveExtension.get()
101+
File archiveFile = archive.archiveFile.get().asFile
102+
if (classifier == "sources") {
103+
fileSystemOperations.copy {
104+
from archiveFile
105+
into sourceFolder
106+
rename {archive.projectName + '-' + classifier + '.' + ext}
107+
}
108+
} else if (classifier == "javadoc") {
109+
fileSystemOperations.copy {
110+
from archiveFile
111+
into javadocFolder
112+
rename {archive.projectName + '-' + classifier + '.' + ext}
113+
}
114+
} else{
115+
fileSystemOperations.copy {
116+
from archiveFile
117+
into libFolder
118+
rename {archive.projectName + '.' + ext}
99119
}
100120
}
101121
}
@@ -146,6 +166,7 @@ def mergedJavadocSubprojects = [
146166
":jme3-terrain",
147167
]
148168
tasks.register('mergedJavadoc', Javadoc) {
169+
dependsOn mergedJavadocSubprojects.collect { project(it).tasks.named('classes') }
149170
description = 'Creates Javadoc from all the projects.'
150171
title = 'jMonkeyEngine3'
151172
destinationDir = file("dist/javadoc")
@@ -157,7 +178,7 @@ tasks.register('mergedJavadoc', Javadoc) {
157178

158179
options.overview = file("javadoc-overview.html")
159180
source = mergedJavadocSubprojects.collect { project(it).sourceSets.main.allJava }
160-
classpath = files(mergedJavadocSubprojects.collect { project(it).sourceSets.main.compileClasspath })
181+
classpath = files(mergedJavadocSubprojects.collect { project(it).sourceSets.main.compileClasspath.files })
161182
}
162183

163184
def cleanMergedJavadoc = tasks.register('cleanMergedJavadoc', Delete) {
@@ -197,45 +218,40 @@ gradle.rootProject.ext.set("usePrebuildNatives", buildNativeProjects!="true");
197218

198219
if (skipPrebuildLibraries != "true" && buildNativeProjects != "true") {
199220
File nativesSnapshotPropF = file('natives-snapshot.properties')
221+
String prebuildNativesUrlTemplate = PREBUILD_NATIVES_URL
200222

201223
if (nativesSnapshotPropF.exists()) {
202-
def readNativesConfig = {
203-
Properties nativesSnapshotProp = new Properties()
204-
nativesSnapshotPropF.withInputStream { nativesSnapshotProp.load(it) }
205-
206-
String nativesSnapshot = nativesSnapshotProp.getProperty("natives.snapshot")
207-
if (!nativesSnapshot) {
208-
throw new GradleException("Missing 'natives.snapshot' in ${nativesSnapshotPropF}")
209-
}
224+
Properties nativesSnapshotProp = new Properties()
225+
nativesSnapshotPropF.withInputStream { nativesSnapshotProp.load(it) }
210226

211-
[
212-
snapshot: nativesSnapshot,
213-
url: PREBUILD_NATIVES_URL.replace('${natives.snapshot}', nativesSnapshot),
214-
zipFile: layout.buildDirectory.file("${nativesSnapshot}-natives.zip"),
215-
nativeDir: layout.buildDirectory.dir("native"),
216-
]
227+
String nativesSnapshot = nativesSnapshotProp.getProperty("natives.snapshot")
228+
if (!nativesSnapshot) {
229+
throw new GradleException("Missing 'natives.snapshot' in ${nativesSnapshotPropF}")
217230
}
218231

219-
def nativesZipFile = providers.provider { readNativesConfig().zipFile.get().asFile }
232+
String nativesUrl = prebuildNativesUrlTemplate.replace('${natives.snapshot}', nativesSnapshot)
233+
File nativesZipFile = layout.buildDirectory.file("${nativesSnapshot}-natives.zip").get().asFile
220234
def nativesPath = layout.buildDirectory.dir("native")
221235

222236
def getNativesZipFile = tasks.register('getNativesZipFile') {
237+
inputs.property('nativesUrl', nativesUrl)
223238
outputs.file(nativesZipFile)
224239
doFirst {
225-
def nativesConfig = readNativesConfig()
226-
File target = nativesConfig.zipFile.get().asFile
227-
println("Use natives snapshot: ${nativesConfig.url}")
228-
println("Download natives from ${nativesConfig.url} to ${target}")
229-
target.getParentFile().mkdirs()
230-
ant.get(src: nativesConfig.url, dest: target)
240+
println("Use natives snapshot: ${nativesUrl}")
241+
println("Download natives from ${nativesUrl} to ${nativesZipFile}")
242+
nativesZipFile.getParentFile().mkdirs()
243+
File tempFile = new File(nativesZipFile.parentFile, "${nativesZipFile.name}.part")
244+
tempFile.delete()
245+
ant.get(src: nativesUrl, dest: tempFile)
246+
Files.move(tempFile.toPath(), nativesZipFile.toPath(), StandardCopyOption.REPLACE_EXISTING)
231247
}
232248
}
233249

234250
def extractPrebuiltNatives = tasks.register('extractPrebuiltNatives', Sync) {
235251
dependsOn(getNativesZipFile)
236252
into(nativesPath)
237253
from({
238-
zipTree(readNativesConfig().zipFile.get().asFile)
254+
zipTree(nativesZipFile)
239255
}) {
240256
eachFile { details ->
241257
def segments = details.relativePath.segments

0 commit comments

Comments
 (0)