build.gradle 9.2 KB

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