2
0

build.gradle 8.1 KB

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