Skip to content

Commit c3e8bf7

Browse files
committed
Clean up Gradle build warnings
1 parent 4bf1a51 commit c3e8bf7

6 files changed

Lines changed: 107 additions & 86 deletions

File tree

build.gradle

Lines changed: 74 additions & 66 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,29 +145,24 @@ 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'
147154

148-
// Allows Javadoc to be generated on Java 8 despite doclint errors.
149-
if (JavaVersion.current().isJava8Compatible()) {
150-
options.addStringOption('Xdoclint:none', '-quiet')
151-
}
152-
153155
options.overview = file("javadoc-overview.html")
154156
source = mergedJavadocSubprojects.collect { project(it).sourceSets.main.allJava }
155157
classpath = files(mergedJavadocSubprojects.collect { project(it).sourceSets.main.compileClasspath })
156158
}
157159

158-
clean.dependsOn('cleanMergedJavadoc')
159-
task cleanMergedJavadoc(type: Delete) {
160+
def cleanMergedJavadoc = tasks.register('cleanMergedJavadoc', Delete) {
160161
delete file('dist/javadoc')
161162
}
162163

163-
task mergedSource(type: Copy){
164-
164+
tasks.named('clean') {
165+
dependsOn cleanMergedJavadoc
165166
}
166167

167168
ext {
@@ -192,54 +193,61 @@ task configureAndroidNDK {
192193
gradle.rootProject.ext.set("usePrebuildNatives", buildNativeProjects!="true");
193194

194195
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");
196+
File nativesSnapshotPropF = file('natives-snapshot.properties')
199197

200198
if (nativesSnapshotPropF.exists()) {
199+
def readNativesConfig = {
200+
Properties nativesSnapshotProp = new Properties()
201+
nativesSnapshotPropF.withInputStream { nativesSnapshotProp.load(it) }
201202

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
203+
String nativesSnapshot = nativesSnapshotProp.getProperty("natives.snapshot")
204+
if (!nativesSnapshot) {
205+
throw new GradleException("Missing 'natives.snapshot' in ${nativesSnapshotPropF}")
206+
}
207207

208-
String nativesZipFile = "${rootPath}" + File.separator + "build" + File.separator + nativesSnapshot + "-natives.zip"
209-
String nativesPath = "${rootPath}" + File.separator + "build" + File.separator + "native"
208+
[
209+
snapshot: nativesSnapshot,
210+
url: PREBUILD_NATIVES_URL.replace('${natives.snapshot}', nativesSnapshot),
211+
zipFile: layout.buildDirectory.file("${nativesSnapshot}-natives.zip"),
212+
nativeDir: layout.buildDirectory.dir("native"),
213+
]
214+
}
210215

216+
def nativesZipFile = providers.provider { readNativesConfig().zipFile.get().asFile }
217+
def nativesPath = layout.buildDirectory.dir("native")
211218

212-
task getNativesZipFile {
213-
outputs.file nativesZipFile
219+
def getNativesZipFile = tasks.register('getNativesZipFile') {
220+
outputs.file(nativesZipFile)
214221
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);
222+
def nativesConfig = readNativesConfig()
223+
File target = nativesConfig.zipFile.get().asFile
224+
println("Use natives snapshot: ${nativesConfig.url}")
225+
println("Download natives from ${nativesConfig.url} to ${target}")
226+
target.getParentFile().mkdirs()
227+
ant.get(src: nativesConfig.url, dest: target)
219228
}
220229
}
221230

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);
231+
def extractPrebuiltNatives = tasks.register('extractPrebuiltNatives', Sync) {
232+
dependsOn(getNativesZipFile)
233+
into(nativesPath)
234+
from({
235+
zipTree(readNativesConfig().zipFile.get().asFile)
236+
}) {
237+
eachFile { details ->
238+
def segments = details.relativePath.segments
239+
if (segments.length <= 1) {
240+
details.exclude()
241+
} else {
242+
details.relativePath = new RelativePath(details.isDirectory(), segments[1..-1] as String[])
238243
}
239244
}
245+
includeEmptyDirs = false
240246
}
241247
}
242248

243-
assemble.dependsOn extractPrebuiltNatives
249+
tasks.named('assemble') {
250+
dependsOn extractPrebuiltNatives
251+
}
244252
}
245-
}
253+
}

common.gradle

Lines changed: 7 additions & 4 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

@@ -209,8 +212,8 @@ tasks.withType(Sign) {
209212
}
210213

211214
checkstyle {
212-
toolVersion libs.versions.checkstyle.get()
213-
configFile file("${gradle.rootProject.rootDir}/config/checkstyle/checkstyle.xml")
215+
toolVersion = libs.versions.checkstyle.get()
216+
configFile = file("${gradle.rootProject.rootDir}/config/checkstyle/checkstyle.xml")
214217
}
215218

216219
checkstyleMain {
@@ -227,4 +230,4 @@ tasks.withType(Checkstyle) {
227230
html.required.set(true)
228231
}
229232
include("**/com/jme3/renderer/**/*.java")
230-
}
233+
}

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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,19 @@ task dist (dependsOn: ['build', ':jme3-android:jar', ':jme3-android-native:jar']
6969
}
7070
}
7171
copy {
72-
from jar.archivePath
72+
from tasks.named('jar').flatMap { it.archiveFile }
7373
into '../dist'
7474
rename { "jMonkeyEngine3.jar" }
7575
}
7676

7777
// Copy android packages, remove version
7878
copy {
79-
from project(':jme3-android').jar.archivePath
79+
from project(':jme3-android').tasks.named('jar').flatMap { it.archiveFile }
8080
into '../dist/opt/android'
8181
rename {project(':jme3-android').name+".jar"}
8282
}
8383
copy {
84-
from project(':jme3-android-native').jar.archivePath
84+
from project(':jme3-android-native').tasks.named('jar').flatMap { it.archiveFile }
8585
into '../dist/opt/android'
8686
rename {project(':jme3-android-native').name+".jar"}
8787
}

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 }

jme3-screenshot-tests/build.gradle

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,21 @@ dependencies {
1616

1717
implementation 'com.aventstack:extentreports:5.1.2'
1818
implementation platform('org.junit:junit-bom:5.9.1')
19-
implementation 'org.junit.jupiter:junit-jupiter'
19+
implementation 'org.junit.jupiter:junit-jupiter-api'
2020
testRuntimeOnly project(':jme3-testdata')
2121
}
2222

23+
testing {
24+
suites {
25+
test {
26+
useJUnitJupiter('5.9.1')
27+
}
28+
}
29+
}
30+
2331
tasks.register("screenshotTest", Test) {
32+
testClassesDirs = sourceSets.test.output.classesDirs
33+
classpath = sourceSets.test.runtimeClasspath
2434
useJUnitPlatform{
2535
filter{
2636
includeTags 'integration'
@@ -35,4 +45,4 @@ test {
3545
excludeTags 'integration'
3646
}
3747
}
38-
}
48+
}

0 commit comments

Comments
 (0)