build.gradle 8.4 KB

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