build.gradle 9.0 KB

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