Skip to content

Commit 6388607

Browse files
authored
Clean up Gradle build warnings (#2700)
1 parent ceec9a3 commit 6388607

File tree

6 files changed

+110
-83
lines changed

6 files changed

+110
-83
lines changed

build.gradle

Lines changed: 73 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import java.nio.file.Files;
2-
import java.nio.file.StandardCopyOption;
3-
41
buildscript {
52
repositories {
63
mavenCentral()
74
google()
85
maven {
9-
url "https://plugins.gradle.org/m2/"
6+
url = "https://plugins.gradle.org/m2/"
107
}
118
}
129
dependencies {
@@ -15,6 +12,14 @@ buildscript {
1512
}
1613
}
1714

15+
import org.gradle.api.file.RelativePath
16+
17+
// Set the license for IDEs that understand this
18+
ext.license = file("$rootDir/source-file-header-template.txt")
19+
20+
apply plugin: 'base'
21+
apply from: file('version.gradle')
22+
1823
allprojects {
1924
repositories {
2025
mavenCentral()
@@ -25,13 +30,6 @@ allprojects {
2530
}
2631
}
2732

28-
// Set the license for IDEs that understand this
29-
ext.license = file("$rootDir/source-file-header-template.txt")
30-
31-
apply plugin: 'base'
32-
apply plugin: 'com.github.spotbugs'
33-
apply from: file('version.gradle')
34-
3533
// This is applied to all sub projects
3634
subprojects {
3735
if(!project.name.equals('jme3-android-examples')) {
@@ -58,13 +56,17 @@ subprojects {
5856
}
5957
}
6058

61-
task run(dependsOn: ':jme3-examples:run') {
59+
tasks.register('run') {
60+
dependsOn ':jme3-examples:run'
6261
description = 'Run the jME3 examples'
6362
}
6463

6564
defaultTasks 'run'
6665

67-
task libDist(dependsOn: subprojects.build, description: 'Builds and copies the engine binaries, sources and javadoc to build/libDist') {
66+
def libDist = tasks.register('libDist') {
67+
dependsOn(subprojects.collect { it.tasks.named('build') })
68+
description = 'Builds and copies the engine binaries, sources and javadoc to build/libDist'
69+
6870
doLast {
6971
File libFolder = mkdir("$buildDir/libDist/lib")
7072
File sourceFolder = mkdir("$buildDir/libDist/sources")
@@ -74,21 +76,22 @@ task libDist(dependsOn: subprojects.build, description: 'Builds and copies the e
7476
project.tasks.withType(Jar).each {archiveTask ->
7577
String classifier = archiveTask.archiveClassifier.get()
7678
String ext = archiveTask.archiveExtension.get()
79+
File archiveFile = archiveTask.archiveFile.get().asFile
7780
if (classifier == "sources") {
7881
copy {
79-
from archiveTask.archivePath
82+
from archiveFile
8083
into sourceFolder
8184
rename {project.name + '-' + classifier + '.' + ext}
8285
}
8386
} else if (classifier == "javadoc") {
8487
copy {
85-
from archiveTask.archivePath
88+
from archiveFile
8689
into javadocFolder
8790
rename {project.name + '-' + classifier + '.' + ext}
8891
}
8992
} else{
9093
copy {
91-
from archiveTask.archivePath
94+
from archiveFile
9295
into libFolder
9396
rename {project.name + '.' + ext}
9497
}
@@ -99,7 +102,9 @@ task libDist(dependsOn: subprojects.build, description: 'Builds and copies the e
99102
}
100103
}
101104

102-
task createZipDistribution(type:Zip,dependsOn:["dist","libDist"], description:"Package the nightly zip distribution"){
105+
tasks.register('createZipDistribution', Zip) {
106+
dependsOn(tasks.named('dist'), libDist)
107+
description = 'Package the nightly zip distribution'
103108
archiveFileName = provider {
104109
"jME" + jmeFullVersion + ".zip"
105110
}
@@ -111,7 +116,7 @@ task createZipDistribution(type:Zip,dependsOn:["dist","libDist"], description:"P
111116
}
112117
}
113118

114-
task copyLibs(type: Copy){
119+
tasks.register('copyLibs', Copy) {
115120
// description 'Copies the engine dependencies to build/libDist'
116121
from {
117122
subprojects*.configurations*.implementation*.copyRecursive({ !(it instanceof ProjectDependency); })*.resolve()
@@ -120,8 +125,9 @@ task copyLibs(type: Copy){
120125
into "$buildDir/libDist/lib-ext" //buildDir.path + '/' + libsDirName + '/lib'
121126
}
122127

123-
task dist(dependsOn: [':jme3-examples:dist', 'mergedJavadoc']){
124-
description 'Creates a jME3 examples distribution with all jme3 binaries, sources, javadoc and external libraries under ./dist'
128+
tasks.register('dist') {
129+
dependsOn ':jme3-examples:dist', tasks.named('mergedJavadoc')
130+
description = 'Creates a jME3 examples distribution with all jme3 binaries, sources, javadoc and external libraries under ./dist'
125131
}
126132

127133
def mergedJavadocSubprojects = [
@@ -139,13 +145,12 @@ def mergedJavadocSubprojects = [
139145
":jme3-plugins",
140146
":jme3-terrain",
141147
]
142-
task mergedJavadoc(type: Javadoc, description: 'Creates Javadoc from all the projects.') {
148+
tasks.register('mergedJavadoc', Javadoc) {
149+
description = 'Creates Javadoc from all the projects.'
143150
title = 'jMonkeyEngine3'
144-
destinationDir = mkdir("dist/javadoc")
151+
destinationDir = file("dist/javadoc")
145152

146153
options.encoding = 'UTF-8'
147-
148-
// Allows Javadoc to be generated on Java 8 despite doclint errors.
149154
if (JavaVersion.current().isJava8Compatible()) {
150155
options.addStringOption('Xdoclint:none', '-quiet')
151156
}
@@ -155,13 +160,12 @@ task mergedJavadoc(type: Javadoc, description: 'Creates Javadoc from all the pro
155160
classpath = files(mergedJavadocSubprojects.collect { project(it).sourceSets.main.compileClasspath })
156161
}
157162

158-
clean.dependsOn('cleanMergedJavadoc')
159-
task cleanMergedJavadoc(type: Delete) {
163+
def cleanMergedJavadoc = tasks.register('cleanMergedJavadoc', Delete) {
160164
delete file('dist/javadoc')
161165
}
162166

163-
task mergedSource(type: Copy){
164-
167+
tasks.named('clean') {
168+
dependsOn cleanMergedJavadoc
165169
}
166170

167171
ext {
@@ -192,54 +196,61 @@ task configureAndroidNDK {
192196
gradle.rootProject.ext.set("usePrebuildNatives", buildNativeProjects!="true");
193197

194198
if (skipPrebuildLibraries != "true" && buildNativeProjects != "true") {
195-
String rootPath = rootProject.projectDir.absolutePath
196-
197-
Properties nativesSnapshotProp = new Properties()
198-
File nativesSnapshotPropF = new File("${rootPath}/natives-snapshot.properties");
199+
File nativesSnapshotPropF = file('natives-snapshot.properties')
199200

200201
if (nativesSnapshotPropF.exists()) {
202+
def readNativesConfig = {
203+
Properties nativesSnapshotProp = new Properties()
204+
nativesSnapshotPropF.withInputStream { nativesSnapshotProp.load(it) }
201205

202-
nativesSnapshotPropF.withInputStream { nativesSnapshotProp.load(it) }
203-
204-
String nativesSnapshot = nativesSnapshotProp.getProperty("natives.snapshot");
205-
String nativesUrl = PREBUILD_NATIVES_URL.replace('${natives.snapshot}', nativesSnapshot)
206-
println "Use natives snapshot: " + nativesUrl
206+
String nativesSnapshot = nativesSnapshotProp.getProperty("natives.snapshot")
207+
if (!nativesSnapshot) {
208+
throw new GradleException("Missing 'natives.snapshot' in ${nativesSnapshotPropF}")
209+
}
207210

208-
String nativesZipFile = "${rootPath}" + File.separator + "build" + File.separator + nativesSnapshot + "-natives.zip"
209-
String nativesPath = "${rootPath}" + File.separator + "build" + File.separator + "native"
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+
]
217+
}
210218

219+
def nativesZipFile = providers.provider { readNativesConfig().zipFile.get().asFile }
220+
def nativesPath = layout.buildDirectory.dir("native")
211221

212-
task getNativesZipFile {
213-
outputs.file nativesZipFile
222+
def getNativesZipFile = tasks.register('getNativesZipFile') {
223+
outputs.file(nativesZipFile)
214224
doFirst {
215-
File target = file(nativesZipFile);
216-
println("Download natives from " + nativesUrl + " to " + nativesZipFile);
217-
target.getParentFile().mkdirs();
218-
ant.get(src: nativesUrl, dest: target);
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)
219231
}
220232
}
221233

222-
task extractPrebuiltNatives {
223-
inputs.file nativesZipFile
224-
outputs.dir nativesPath
225-
dependsOn getNativesZipFile
226-
227-
doFirst {
228-
for (File src : zipTree(nativesZipFile)) {
229-
String srcRel = src.getAbsolutePath().substring((int) (nativesZipFile.length() + 1));
230-
srcRel = srcRel.substring(srcRel.indexOf(File.separator) + 1);
231-
232-
File dest = new File(nativesPath + File.separator + srcRel);
233-
boolean doCopy = !(dest.exists() && dest.lastModified() > src.lastModified())
234-
if (doCopy) {
235-
println("Copy " + src + " " + dest);
236-
dest.getParentFile().mkdirs();
237-
Files.copy(src.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING);
234+
def extractPrebuiltNatives = tasks.register('extractPrebuiltNatives', Sync) {
235+
dependsOn(getNativesZipFile)
236+
into(nativesPath)
237+
from({
238+
zipTree(readNativesConfig().zipFile.get().asFile)
239+
}) {
240+
eachFile { details ->
241+
def segments = details.relativePath.segments
242+
if (segments.length <= 1) {
243+
details.exclude()
244+
} else {
245+
details.relativePath = new RelativePath(details.isDirectory(), segments[1..-1] as String[])
238246
}
239247
}
248+
includeEmptyDirs = false
240249
}
241250
}
242251

243-
assemble.dependsOn extractPrebuiltNatives
252+
tasks.named('assemble') {
253+
dependsOn extractPrebuiltNatives
254+
}
244255
}
245256
}

common.gradle

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ javadoc {
7272
options.use = "true"
7373
options.charSet = "UTF-8"
7474
options.encoding = "UTF-8"
75+
if (JavaVersion.current().isJava8Compatible()) {
76+
options.addStringOption('Xdoclint:none', '-quiet')
77+
}
7578
source = sourceSets.main.allJava // main only, exclude tests
7679
}
7780

@@ -154,7 +157,7 @@ publishing {
154157
}
155158
url = POM_URL
156159
}
157-
version project.version
160+
version = project.version
158161
}
159162
}
160163

@@ -211,8 +214,8 @@ tasks.withType(Sign) {
211214
def checkstyleSupported = JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_21)
212215

213216
checkstyle {
214-
toolVersion libs.versions.checkstyle.get()
215-
configFile file("${gradle.rootProject.rootDir}/config/checkstyle/checkstyle.xml")
217+
toolVersion = libs.versions.checkstyle.get()
218+
configFile = file("${gradle.rootProject.rootDir}/config/checkstyle/checkstyle.xml")
216219
}
217220

218221
checkstyleMain {

jme3-android/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
apply plugin: 'java'
2-
31
dependencies {
42
//added annotations used by JmeSurfaceView.
53
compileOnly libs.androidx.annotation
64
compileOnly libs.androidx.lifecycle.common
75
api project(':jme3-core')
8-
compileOnly 'android:android'
6+
compileOnly files(rootProject.file('lib/android.jar'))
97
}
108

119
compileJava {

jme3-examples/build.gradle

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
ext.mainClassName = 'jme3test.TestChooser'
22

3+
def androidProject = project(':jme3-android')
4+
def androidNativeProject = project(':jme3-android-native')
5+
36
task run(dependsOn: 'build', type:JavaExec) {
47
mainClass = mainClassName
58
classpath = sourceSets.main.runtimeClasspath
@@ -69,21 +72,21 @@ task dist (dependsOn: ['build', ':jme3-android:jar', ':jme3-android-native:jar']
6972
}
7073
}
7174
copy {
72-
from jar.archivePath
75+
from tasks.named('jar').flatMap { it.archiveFile }
7376
into '../dist'
7477
rename { "jMonkeyEngine3.jar" }
7578
}
7679

7780
// Copy android packages, remove version
7881
copy {
79-
from project(':jme3-android').jar.archivePath
82+
from androidProject.tasks.named('jar').flatMap { it.archiveFile }
8083
into '../dist/opt/android'
81-
rename {project(':jme3-android').name+".jar"}
84+
rename { androidProject.name + ".jar" }
8285
}
8386
copy {
84-
from project(':jme3-android-native').jar.archivePath
87+
from androidNativeProject.tasks.named('jar').flatMap { it.archiveFile }
8588
into '../dist/opt/android'
86-
rename {project(':jme3-android-native').name+".jar"}
89+
rename { androidNativeProject.name + ".jar" }
8790
}
8891
}
8992
}

jme3-ios-native/build.gradle

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
import org.apache.tools.ant.taskdefs.condition.Os
22

3-
task deleteXcframework(type: Delete) {
3+
def deleteXcframework = tasks.register('deleteXcframework', Delete) {
44
delete 'template/META-INF/robovm/ios/libs/jme3-ios-native.xcframework'
55
}
66

7-
task buildNativeLibIos(type: Exec) {
7+
def buildNativeLibIos = tasks.register('buildNativeLibIos', Exec) {
88
executable "xcodebuild"
99
args 'archive', '-project', 'jme3-ios-native.xcodeproj', '-scheme', 'jme3-ios-native', '-configuration', 'release', '-destination', 'generic/platform=iOS', '-archivePath', 'build/archives/jme3-ios-native_iOS', 'SKIP_INSTALL=NO', 'BUILD_LIBRARY_FOR_DISTRIBUTION=YES'
1010
}
1111

12-
task buildNativeLibSimulator(type: Exec) {
12+
def buildNativeLibSimulator = tasks.register('buildNativeLibSimulator', Exec) {
1313
executable "xcodebuild"
1414
args 'archive', '-project', 'jme3-ios-native.xcodeproj', '-scheme', 'jme3-ios-native', '-configuration', 'release', '-destination', 'generic/platform=iOS Simulator', '-archivePath', 'build/archives/jme3-ios-native_iOS-Simulator', 'SKIP_INSTALL=NO', 'BUILD_LIBRARY_FOR_DISTRIBUTION=YES'
1515
}
1616

17-
task buildNativeLib(type: Exec) {
18-
dependsOn 'deleteXcframework'
19-
dependsOn 'buildNativeLibIos'
20-
dependsOn 'buildNativeLibSimulator'
17+
def buildNativeLib = tasks.register('buildNativeLib', Exec) {
18+
dependsOn deleteXcframework
19+
dependsOn buildNativeLibIos
20+
dependsOn buildNativeLibSimulator
2121
executable "xcodebuild"
2222
args '-create-xcframework', '-framework', 'build/archives/jme3-ios-native_iOS.xcarchive/Products/Library/Frameworks/jme3_ios_native.framework', '-framework', 'build/archives/jme3-ios-native_iOS-Simulator.xcarchive/Products/Library/Frameworks/jme3_ios_native.framework', '-output', 'template/META-INF/robovm/ios/libs/jme3-ios-native.xcframework'
2323
}
2424

2525
// buildNativeProjects is a string set to "true"
2626
if (Os.isFamily(Os.FAMILY_MAC) && buildNativeProjects == "true") {
2727
// build native libs and update stored pre-compiled libs to commit
28-
compileJava.dependsOn { buildNativeLib }
28+
tasks.named('compileJava') {
29+
dependsOn buildNativeLib
30+
}
2931
} else {
3032
// TODO: (like android natives?) use pre-compiled native libs (not building new ones)
3133
// compileJava.dependsOn { copyPreCompiledLibs }

0 commit comments

Comments
 (0)