build.gradle 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. import java.nio.file.Files;
  2. import java.nio.file.StandardCopyOption;
  3. buildscript {
  4. repositories {
  5. mavenCentral()
  6. google()
  7. maven {
  8. url "https://plugins.gradle.org/m2/"
  9. }
  10. }
  11. dependencies {
  12. classpath 'com.android.tools.build:gradle:4.2.0'
  13. classpath 'me.tatarka:gradle-retrolambda:3.7.1'
  14. classpath "gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.5.1"
  15. }
  16. }
  17. allprojects {
  18. repositories {
  19. mavenCentral()
  20. google()
  21. }
  22. tasks.withType(Jar) {
  23. duplicatesStrategy = 'include'
  24. }
  25. }
  26. // Set the license for IDEs that understand this
  27. ext.license = file("$rootDir/license.txt")
  28. apply plugin: 'base'
  29. apply plugin: 'com.github.spotbugs'
  30. apply from: file('version.gradle')
  31. apply plugin: 'me.tatarka.retrolambda'
  32. // This is applied to all sub projects
  33. subprojects {
  34. if(!project.name.equals('jme3-android-examples')) {
  35. apply from: rootProject.file('common.gradle')
  36. } else {
  37. apply from: rootProject.file('common-android-app.gradle')
  38. }
  39. if (!project.name.endsWith("-native") && enableSpotBugs != "false" ) {
  40. apply plugin: 'com.github.spotbugs'
  41. // Currently we only warn about issues and try to fix them as we go, but those aren't mission critical.
  42. spotbugs {
  43. ignoreFailures = true
  44. }
  45. tasks.withType(com.github.spotbugs.snom.SpotBugsTask ) {
  46. reports {
  47. html.enabled = !project.hasProperty("xml-reports")
  48. xml.enabled = project.hasProperty("xml-reports")
  49. }
  50. }
  51. }
  52. }
  53. task run(dependsOn: ':jme3-examples:run') {
  54. description = 'Run the jME3 examples'
  55. }
  56. defaultTasks 'run'
  57. task libDist(dependsOn: subprojects.build, description: 'Builds and copies the engine binaries, sources and javadoc to build/libDist') {
  58. doLast {
  59. File libFolder = mkdir("$buildDir/libDist/lib")
  60. File sourceFolder = mkdir("$buildDir/libDist/sources")
  61. File javadocFolder = mkdir("$buildDir/libDist/javadoc")
  62. subprojects.each {project ->
  63. if(!project.hasProperty('mainClassName')){
  64. project.tasks.withType(Jar).each {archiveTask ->
  65. if(archiveTask.classifier == "sources"){
  66. copy {
  67. from archiveTask.archivePath
  68. into sourceFolder
  69. rename {project.name + '-' + archiveTask.classifier +'.'+ archiveTask.extension}
  70. }
  71. } else if(archiveTask.classifier == "javadoc"){
  72. copy {
  73. from archiveTask.archivePath
  74. into javadocFolder
  75. rename {project.name + '-' + archiveTask.classifier +'.'+ archiveTask.extension}
  76. }
  77. } else{
  78. copy {
  79. from archiveTask.archivePath
  80. into libFolder
  81. rename {project.name + '.' + archiveTask.extension}
  82. }
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }
  89. task createZipDistribution(type:Zip,dependsOn:["dist","libDist"], description:"Package the nightly zip distribution"){
  90. archiveFileName = provider {
  91. "jME" + jmeFullVersion + ".zip"
  92. }
  93. into("/") {
  94. from {"./dist"}
  95. }
  96. into("/sources") {
  97. from {"$buildDir/libDist/sources"}
  98. }
  99. }
  100. task copyLibs(type: Copy){
  101. // description 'Copies the engine dependencies to build/libDist'
  102. from {
  103. subprojects*.configurations*.compile*.copyRecursive({ !(it instanceof ProjectDependency); })*.resolve()
  104. }
  105. into "$buildDir/libDist/lib-ext" //buildDir.path + '/' + libsDirName + '/lib'
  106. }
  107. task dist(dependsOn: [':jme3-examples:dist', 'mergedJavadoc']){
  108. description 'Creates a jME3 examples distribution with all jme3 binaries, sources, javadoc and external libraries under ./dist'
  109. }
  110. task mergedJavadoc(type: Javadoc, description: 'Creates Javadoc from all the projects.') {
  111. title = 'jMonkeyEngine3'
  112. destinationDir = mkdir("dist/javadoc")
  113. options.encoding = 'UTF-8'
  114. // Allows Javadoc to be generated on Java 8 despite doclint errors.
  115. if (JavaVersion.current().isJava8Compatible()) {
  116. options.addStringOption('Xdoclint:none', '-quiet')
  117. }
  118. options.overview = file("javadoc-overview.html")
  119. // Note: The closures below are executed lazily.
  120. source subprojects.collect {project ->
  121. project.sourceSets.main.allJava // main only, exclude tests
  122. }
  123. classpath = files(subprojects.collect {project ->
  124. project.sourceSets*.compileClasspath})
  125. classpath.from {
  126. subprojects*.configurations*.compile*.copyRecursive({ !(it instanceof ProjectDependency); })*.resolve()
  127. }
  128. }
  129. clean.dependsOn('cleanMergedJavadoc')
  130. task cleanMergedJavadoc(type: Delete) {
  131. delete file('dist/javadoc')
  132. }
  133. task mergedSource(type: Copy){
  134. }
  135. ext {
  136. ndkCommandPath = ""
  137. ndkExists = false
  138. }
  139. task configureAndroidNDK {
  140. def ndkBuildFile = "ndk-build"
  141. // if windows, use ndk-build.cmd instead
  142. if (System.properties['os.name'].toLowerCase().contains('windows')) {
  143. ndkBuildFile = "ndk-build.cmd"
  144. }
  145. // ndkPath is defined in the root project gradle.properties file
  146. String ndkBuildPath = ndkPath + File.separator + ndkBuildFile
  147. //Use the environment variable for the NDK location if defined
  148. if (System.env.ANDROID_NDK != null) {
  149. ndkBuildPath = System.env.ANDROID_NDK + File.separator + ndkBuildFile
  150. }
  151. if (new File(ndkBuildPath).exists()) {
  152. ndkExists = true
  153. ndkCommandPath = ndkBuildPath
  154. }
  155. }
  156. gradle.rootProject.ext.set("usePrebuildNatives", buildNativeProjects!="true");
  157. if (skipPrebuildLibraries != "true" && buildNativeProjects != "true") {
  158. String rootPath = rootProject.projectDir.absolutePath
  159. Properties nativesSnapshotProp = new Properties()
  160. File nativesSnapshotPropF = new File("${rootPath}/natives-snapshot.properties");
  161. if (nativesSnapshotPropF.exists()) {
  162. nativesSnapshotPropF.withInputStream { nativesSnapshotProp.load(it) }
  163. String nativesSnapshot = nativesSnapshotProp.getProperty("natives.snapshot");
  164. String nativesUrl = PREBUILD_NATIVES_URL.replace('${natives.snapshot}', nativesSnapshot)
  165. println "Use natives snapshot: " + nativesUrl
  166. String nativesZipFile = "${rootPath}" + File.separator + "build" + File.separator + nativesSnapshot + "-natives.zip"
  167. String nativesPath = "${rootPath}" + File.separator + "build" + File.separator + "native"
  168. task getNativesZipFile {
  169. outputs.file nativesZipFile
  170. doFirst {
  171. File target = file(nativesZipFile);
  172. println("Download natives from " + nativesUrl + " to " + nativesZipFile);
  173. target.getParentFile().mkdirs();
  174. ant.get(src: nativesUrl, dest: target);
  175. }
  176. }
  177. task extractPrebuiltNatives {
  178. inputs.file nativesZipFile
  179. outputs.dir nativesPath
  180. dependsOn getNativesZipFile
  181. doFirst {
  182. for (File src : zipTree(nativesZipFile)) {
  183. String srcRel = src.getAbsolutePath().substring((int) (nativesZipFile.length() + 1));
  184. srcRel = srcRel.substring(srcRel.indexOf(File.separator) + 1);
  185. File dest = new File(nativesPath + File.separator + srcRel);
  186. boolean doCopy = !(dest.exists() && dest.lastModified() > src.lastModified())
  187. if (doCopy) {
  188. println("Copy " + src + " " + dest);
  189. dest.getParentFile().mkdirs();
  190. Files.copy(src.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING);
  191. }
  192. }
  193. }
  194. }
  195. assemble.dependsOn extractPrebuiltNatives
  196. }
  197. }
  198. //class IncrementalReverseTask extends DefaultTask {
  199. // @InputDirectory
  200. // def File inputDir
  201. //
  202. // @OutputDirectory
  203. // def File outputDir
  204. //
  205. // @Input
  206. // def inputProperty
  207. //
  208. // @TaskAction
  209. // void execute(IncrementalTaskInputs inputs) {
  210. // println inputs.incremental ? "CHANGED inputs considered out of date" : "ALL inputs considered out of date"
  211. // inputs.outOfDate { change ->
  212. // println "out of date: ${change.file.name}"
  213. // def targetFile = new File(outputDir, change.file.name)
  214. // targetFile.text = change.file.text.reverse()
  215. // }
  216. //
  217. // inputs.removed { change ->
  218. // println "removed: ${change.file.name}"
  219. // def targetFile = new File(outputDir, change.file.name)
  220. // targetFile.delete()
  221. // }
  222. // }
  223. //}
  224. //allprojects {
  225. // tasks.withType(JavaExec) {
  226. // enableAssertions = true // false by default
  227. // }
  228. // tasks.withType(Test) {
  229. // enableAssertions = true // true by default
  230. // }
  231. //}
  232. wrapper {
  233. gradleVersion = '6.9.1'
  234. }
  235. retrolambda {
  236. javaVersion JavaVersion.VERSION_1_7
  237. incremental true
  238. jvmArgs '-noverify'
  239. }