diff --git a/build.gradle b/build.gradle index 7976b3d6ff..142f96a3a0 100644 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,9 @@ -import java.nio.file.Files; -import java.nio.file.StandardCopyOption; - buildscript { repositories { mavenCentral() google() maven { - url "https://plugins.gradle.org/m2/" + url = "https://plugins.gradle.org/m2/" } } dependencies { @@ -15,6 +12,14 @@ buildscript { } } +import org.gradle.api.file.RelativePath + +// Set the license for IDEs that understand this +ext.license = file("$rootDir/source-file-header-template.txt") + +apply plugin: 'base' +apply from: file('version.gradle') + allprojects { repositories { mavenCentral() @@ -25,13 +30,6 @@ allprojects { } } -// Set the license for IDEs that understand this -ext.license = file("$rootDir/source-file-header-template.txt") - -apply plugin: 'base' -apply plugin: 'com.github.spotbugs' -apply from: file('version.gradle') - // This is applied to all sub projects subprojects { if(!project.name.equals('jme3-android-examples')) { @@ -58,13 +56,17 @@ subprojects { } } -task run(dependsOn: ':jme3-examples:run') { +tasks.register('run') { + dependsOn ':jme3-examples:run' description = 'Run the jME3 examples' } defaultTasks 'run' -task libDist(dependsOn: subprojects.build, description: 'Builds and copies the engine binaries, sources and javadoc to build/libDist') { +def libDist = tasks.register('libDist') { + dependsOn(subprojects.collect { it.tasks.named('build') }) + description = 'Builds and copies the engine binaries, sources and javadoc to build/libDist' + doLast { File libFolder = mkdir("$buildDir/libDist/lib") File sourceFolder = mkdir("$buildDir/libDist/sources") @@ -74,21 +76,22 @@ task libDist(dependsOn: subprojects.build, description: 'Builds and copies the e project.tasks.withType(Jar).each {archiveTask -> String classifier = archiveTask.archiveClassifier.get() String ext = archiveTask.archiveExtension.get() + File archiveFile = archiveTask.archiveFile.get().asFile if (classifier == "sources") { copy { - from archiveTask.archivePath + from archiveFile into sourceFolder rename {project.name + '-' + classifier + '.' + ext} } } else if (classifier == "javadoc") { copy { - from archiveTask.archivePath + from archiveFile into javadocFolder rename {project.name + '-' + classifier + '.' + ext} } } else{ copy { - from archiveTask.archivePath + from archiveFile into libFolder rename {project.name + '.' + ext} } @@ -99,7 +102,9 @@ task libDist(dependsOn: subprojects.build, description: 'Builds and copies the e } } -task createZipDistribution(type:Zip,dependsOn:["dist","libDist"], description:"Package the nightly zip distribution"){ +tasks.register('createZipDistribution', Zip) { + dependsOn(tasks.named('dist'), libDist) + description = 'Package the nightly zip distribution' archiveFileName = provider { "jME" + jmeFullVersion + ".zip" } @@ -111,7 +116,7 @@ task createZipDistribution(type:Zip,dependsOn:["dist","libDist"], description:"P } } -task copyLibs(type: Copy){ +tasks.register('copyLibs', Copy) { // description 'Copies the engine dependencies to build/libDist' from { subprojects*.configurations*.implementation*.copyRecursive({ !(it instanceof ProjectDependency); })*.resolve() @@ -120,8 +125,9 @@ task copyLibs(type: Copy){ into "$buildDir/libDist/lib-ext" //buildDir.path + '/' + libsDirName + '/lib' } -task dist(dependsOn: [':jme3-examples:dist', 'mergedJavadoc']){ - description 'Creates a jME3 examples distribution with all jme3 binaries, sources, javadoc and external libraries under ./dist' +tasks.register('dist') { + dependsOn ':jme3-examples:dist', tasks.named('mergedJavadoc') + description = 'Creates a jME3 examples distribution with all jme3 binaries, sources, javadoc and external libraries under ./dist' } def mergedJavadocSubprojects = [ @@ -139,13 +145,12 @@ def mergedJavadocSubprojects = [ ":jme3-plugins", ":jme3-terrain", ] -task mergedJavadoc(type: Javadoc, description: 'Creates Javadoc from all the projects.') { +tasks.register('mergedJavadoc', Javadoc) { + description = 'Creates Javadoc from all the projects.' title = 'jMonkeyEngine3' - destinationDir = mkdir("dist/javadoc") + destinationDir = file("dist/javadoc") options.encoding = 'UTF-8' - - // Allows Javadoc to be generated on Java 8 despite doclint errors. if (JavaVersion.current().isJava8Compatible()) { options.addStringOption('Xdoclint:none', '-quiet') } @@ -155,13 +160,12 @@ task mergedJavadoc(type: Javadoc, description: 'Creates Javadoc from all the pro classpath = files(mergedJavadocSubprojects.collect { project(it).sourceSets.main.compileClasspath }) } -clean.dependsOn('cleanMergedJavadoc') -task cleanMergedJavadoc(type: Delete) { +def cleanMergedJavadoc = tasks.register('cleanMergedJavadoc', Delete) { delete file('dist/javadoc') } -task mergedSource(type: Copy){ - +tasks.named('clean') { + dependsOn cleanMergedJavadoc } ext { @@ -192,54 +196,61 @@ task configureAndroidNDK { gradle.rootProject.ext.set("usePrebuildNatives", buildNativeProjects!="true"); if (skipPrebuildLibraries != "true" && buildNativeProjects != "true") { - String rootPath = rootProject.projectDir.absolutePath - - Properties nativesSnapshotProp = new Properties() - File nativesSnapshotPropF = new File("${rootPath}/natives-snapshot.properties"); + File nativesSnapshotPropF = file('natives-snapshot.properties') if (nativesSnapshotPropF.exists()) { + def readNativesConfig = { + Properties nativesSnapshotProp = new Properties() + nativesSnapshotPropF.withInputStream { nativesSnapshotProp.load(it) } - nativesSnapshotPropF.withInputStream { nativesSnapshotProp.load(it) } - - String nativesSnapshot = nativesSnapshotProp.getProperty("natives.snapshot"); - String nativesUrl = PREBUILD_NATIVES_URL.replace('${natives.snapshot}', nativesSnapshot) - println "Use natives snapshot: " + nativesUrl + String nativesSnapshot = nativesSnapshotProp.getProperty("natives.snapshot") + if (!nativesSnapshot) { + throw new GradleException("Missing 'natives.snapshot' in ${nativesSnapshotPropF}") + } - String nativesZipFile = "${rootPath}" + File.separator + "build" + File.separator + nativesSnapshot + "-natives.zip" - String nativesPath = "${rootPath}" + File.separator + "build" + File.separator + "native" + [ + snapshot: nativesSnapshot, + url: PREBUILD_NATIVES_URL.replace('${natives.snapshot}', nativesSnapshot), + zipFile: layout.buildDirectory.file("${nativesSnapshot}-natives.zip"), + nativeDir: layout.buildDirectory.dir("native"), + ] + } + def nativesZipFile = providers.provider { readNativesConfig().zipFile.get().asFile } + def nativesPath = layout.buildDirectory.dir("native") - task getNativesZipFile { - outputs.file nativesZipFile + def getNativesZipFile = tasks.register('getNativesZipFile') { + outputs.file(nativesZipFile) doFirst { - File target = file(nativesZipFile); - println("Download natives from " + nativesUrl + " to " + nativesZipFile); - target.getParentFile().mkdirs(); - ant.get(src: nativesUrl, dest: target); + def nativesConfig = readNativesConfig() + File target = nativesConfig.zipFile.get().asFile + println("Use natives snapshot: ${nativesConfig.url}") + println("Download natives from ${nativesConfig.url} to ${target}") + target.getParentFile().mkdirs() + ant.get(src: nativesConfig.url, dest: target) } } - task extractPrebuiltNatives { - inputs.file nativesZipFile - outputs.dir nativesPath - dependsOn getNativesZipFile - - doFirst { - for (File src : zipTree(nativesZipFile)) { - String srcRel = src.getAbsolutePath().substring((int) (nativesZipFile.length() + 1)); - srcRel = srcRel.substring(srcRel.indexOf(File.separator) + 1); - - File dest = new File(nativesPath + File.separator + srcRel); - boolean doCopy = !(dest.exists() && dest.lastModified() > src.lastModified()) - if (doCopy) { - println("Copy " + src + " " + dest); - dest.getParentFile().mkdirs(); - Files.copy(src.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING); + def extractPrebuiltNatives = tasks.register('extractPrebuiltNatives', Sync) { + dependsOn(getNativesZipFile) + into(nativesPath) + from({ + zipTree(readNativesConfig().zipFile.get().asFile) + }) { + eachFile { details -> + def segments = details.relativePath.segments + if (segments.length <= 1) { + details.exclude() + } else { + details.relativePath = new RelativePath(details.isDirectory(), segments[1..-1] as String[]) } } + includeEmptyDirs = false } } - assemble.dependsOn extractPrebuiltNatives + tasks.named('assemble') { + dependsOn extractPrebuiltNatives + } } -} \ No newline at end of file +} diff --git a/common.gradle b/common.gradle index 042d88e3b5..f0bcba438c 100644 --- a/common.gradle +++ b/common.gradle @@ -72,6 +72,9 @@ javadoc { options.use = "true" options.charSet = "UTF-8" options.encoding = "UTF-8" + if (JavaVersion.current().isJava8Compatible()) { + options.addStringOption('Xdoclint:none', '-quiet') + } source = sourceSets.main.allJava // main only, exclude tests } @@ -154,7 +157,7 @@ publishing { } url = POM_URL } - version project.version + version = project.version } } @@ -209,8 +212,8 @@ tasks.withType(Sign) { } checkstyle { - toolVersion libs.versions.checkstyle.get() - configFile file("${gradle.rootProject.rootDir}/config/checkstyle/checkstyle.xml") + toolVersion = libs.versions.checkstyle.get() + configFile = file("${gradle.rootProject.rootDir}/config/checkstyle/checkstyle.xml") } checkstyleMain { @@ -227,4 +230,4 @@ tasks.withType(Checkstyle) { html.required.set(true) } include("**/com/jme3/renderer/**/*.java") -} \ No newline at end of file +} diff --git a/jme3-android/build.gradle b/jme3-android/build.gradle index 4fa73b50ca..bfe69898f9 100644 --- a/jme3-android/build.gradle +++ b/jme3-android/build.gradle @@ -1,11 +1,9 @@ -apply plugin: 'java' - dependencies { //added annotations used by JmeSurfaceView. compileOnly libs.androidx.annotation compileOnly libs.androidx.lifecycle.common api project(':jme3-core') - compileOnly 'android:android' + compileOnly files(rootProject.file('lib/android.jar')) } compileJava { diff --git a/jme3-examples/build.gradle b/jme3-examples/build.gradle index 1f1d0f286c..b3468883cc 100644 --- a/jme3-examples/build.gradle +++ b/jme3-examples/build.gradle @@ -1,5 +1,8 @@ ext.mainClassName = 'jme3test.TestChooser' +def androidProject = project(':jme3-android') +def androidNativeProject = project(':jme3-android-native') + task run(dependsOn: 'build', type:JavaExec) { mainClass = mainClassName classpath = sourceSets.main.runtimeClasspath @@ -69,21 +72,21 @@ task dist (dependsOn: ['build', ':jme3-android:jar', ':jme3-android-native:jar'] } } copy { - from jar.archivePath + from tasks.named('jar').flatMap { it.archiveFile } into '../dist' rename { "jMonkeyEngine3.jar" } } // Copy android packages, remove version copy { - from project(':jme3-android').jar.archivePath + from androidProject.tasks.named('jar').flatMap { it.archiveFile } into '../dist/opt/android' - rename {project(':jme3-android').name+".jar"} + rename { androidProject.name + ".jar" } } copy { - from project(':jme3-android-native').jar.archivePath + from androidNativeProject.tasks.named('jar').flatMap { it.archiveFile } into '../dist/opt/android' - rename {project(':jme3-android-native').name+".jar"} + rename { androidNativeProject.name + ".jar" } } } } diff --git a/jme3-ios-native/build.gradle b/jme3-ios-native/build.gradle index 75dc000b40..5f0b6304bd 100644 --- a/jme3-ios-native/build.gradle +++ b/jme3-ios-native/build.gradle @@ -1,23 +1,23 @@ import org.apache.tools.ant.taskdefs.condition.Os -task deleteXcframework(type: Delete) { +def deleteXcframework = tasks.register('deleteXcframework', Delete) { delete 'template/META-INF/robovm/ios/libs/jme3-ios-native.xcframework' } -task buildNativeLibIos(type: Exec) { +def buildNativeLibIos = tasks.register('buildNativeLibIos', Exec) { executable "xcodebuild" 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' } -task buildNativeLibSimulator(type: Exec) { +def buildNativeLibSimulator = tasks.register('buildNativeLibSimulator', Exec) { executable "xcodebuild" 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' } -task buildNativeLib(type: Exec) { - dependsOn 'deleteXcframework' - dependsOn 'buildNativeLibIos' - dependsOn 'buildNativeLibSimulator' +def buildNativeLib = tasks.register('buildNativeLib', Exec) { + dependsOn deleteXcframework + dependsOn buildNativeLibIos + dependsOn buildNativeLibSimulator executable "xcodebuild" 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' } @@ -25,7 +25,9 @@ task buildNativeLib(type: Exec) { // buildNativeProjects is a string set to "true" if (Os.isFamily(Os.FAMILY_MAC) && buildNativeProjects == "true") { // build native libs and update stored pre-compiled libs to commit - compileJava.dependsOn { buildNativeLib } + tasks.named('compileJava') { + dependsOn buildNativeLib + } } else { // TODO: (like android natives?) use pre-compiled native libs (not building new ones) // compileJava.dependsOn { copyPreCompiledLibs } diff --git a/jme3-screenshot-tests/build.gradle b/jme3-screenshot-tests/build.gradle index 13cb98d572..fdc8b92be5 100644 --- a/jme3-screenshot-tests/build.gradle +++ b/jme3-screenshot-tests/build.gradle @@ -16,11 +16,21 @@ dependencies { implementation 'com.aventstack:extentreports:5.1.2' implementation platform('org.junit:junit-bom:5.9.1') - implementation 'org.junit.jupiter:junit-jupiter' + implementation 'org.junit.jupiter:junit-jupiter-api' testRuntimeOnly project(':jme3-testdata') } +testing { + suites { + test { + useJUnitJupiter('5.9.1') + } + } +} + tasks.register("screenshotTest", Test) { + testClassesDirs = sourceSets.test.output.classesDirs + classpath = sourceSets.test.runtimeClasspath useJUnitPlatform{ filter{ includeTags 'integration' @@ -35,4 +45,4 @@ test { excludeTags 'integration' } } -} \ No newline at end of file +}