build.gradle 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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") && 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.main.allJava // main only, exclude tests
  121. }
  122. classpath = files(subprojects.collect {project ->
  123. project.sourceSets*.compileClasspath})
  124. classpath.from {
  125. subprojects*.configurations*.compile*.copyRecursive({ !(it instanceof ProjectDependency); })*.resolve()
  126. }
  127. }
  128. clean.dependsOn('cleanMergedJavadoc')
  129. task cleanMergedJavadoc(type: Delete) {
  130. delete file('dist/javadoc')
  131. }
  132. task mergedSource(type: Copy){
  133. }
  134. ext {
  135. ndkCommandPath = ""
  136. ndkExists = false
  137. }
  138. task configureAndroidNDK {
  139. def ndkBuildFile = "ndk-build"
  140. // if windows, use ndk-build.cmd instead
  141. if (System.properties['os.name'].toLowerCase().contains('windows')) {
  142. ndkBuildFile = "ndk-build.cmd"
  143. }
  144. // ndkPath is defined in the root project gradle.properties file
  145. String ndkBuildPath = ndkPath + File.separator + ndkBuildFile
  146. //Use the environment variable for the NDK location if defined
  147. if (System.env.ANDROID_NDK != null) {
  148. ndkBuildPath = System.env.ANDROID_NDK + File.separator + ndkBuildFile
  149. }
  150. if (new File(ndkBuildPath).exists()) {
  151. ndkExists = true
  152. ndkCommandPath = ndkBuildPath
  153. }
  154. }
  155. gradle.rootProject.ext.set("usePrebuildNatives", buildNativeProjects!="true");
  156. if (skipPrebuildLibraries != "true" && buildNativeProjects != "true") {
  157. String rootPath = rootProject.projectDir.absolutePath
  158. Properties nativesSnasphotProp = new Properties()
  159. File nativesSnasphotPropF = new File("${rootPath}/natives-snapshot.properties");
  160. if (nativesSnasphotPropF.exists()) {
  161. nativesSnasphotPropF.withInputStream { nativesSnasphotProp.load(it) }
  162. String nativesSnasphot = nativesSnasphotProp.getProperty("natives.snapshot");
  163. String nativesUrl = PREBUILD_NATIVES_URL.replace('${natives.snapshot}', nativesSnasphot)
  164. println "Use natives snapshot: " + nativesUrl
  165. String nativesZipFile = "${rootPath}" + File.separator + "build" + File.separator + nativesSnasphot + "-natives.zip"
  166. String nativesPath = "${rootPath}" + File.separator + "build" + File.separator + "native"
  167. task getNativesZipFile {
  168. outputs.file nativesZipFile
  169. doFirst {
  170. File target = file(nativesZipFile);
  171. println("Download natives from " + nativesUrl + " to " + nativesZipFile);
  172. target.getParentFile().mkdirs();
  173. ant.get(src: nativesUrl, dest: target);
  174. }
  175. }
  176. task extractPrebuiltNatives {
  177. inputs.file nativesZipFile
  178. outputs.dir nativesPath
  179. dependsOn getNativesZipFile
  180. doFirst {
  181. for (File src : zipTree(nativesZipFile)) {
  182. String srcRel = src.getAbsolutePath().substring((int) (nativesZipFile.length() + 1));
  183. srcRel = srcRel.substring(srcRel.indexOf(File.separator) + 1);
  184. File dest = new File(nativesPath + File.separator + srcRel);
  185. boolean doCopy = !(dest.exists() && dest.lastModified() > src.lastModified())
  186. if (doCopy) {
  187. println("Copy " + src + " " + dest);
  188. dest.getParentFile().mkdirs();
  189. Files.copy(src.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING);
  190. }
  191. }
  192. }
  193. }
  194. assemble.dependsOn extractPrebuiltNatives
  195. }
  196. }
  197. //class IncrementalReverseTask extends DefaultTask {
  198. // @InputDirectory
  199. // def File inputDir
  200. //
  201. // @OutputDirectory
  202. // def File outputDir
  203. //
  204. // @Input
  205. // def inputProperty
  206. //
  207. // @TaskAction
  208. // void execute(IncrementalTaskInputs inputs) {
  209. // println inputs.incremental ? "CHANGED inputs considered out of date" : "ALL inputs considered out of date"
  210. // inputs.outOfDate { change ->
  211. // println "out of date: ${change.file.name}"
  212. // def targetFile = new File(outputDir, change.file.name)
  213. // targetFile.text = change.file.text.reverse()
  214. // }
  215. //
  216. // inputs.removed { change ->
  217. // println "removed: ${change.file.name}"
  218. // def targetFile = new File(outputDir, change.file.name)
  219. // targetFile.delete()
  220. // }
  221. // }
  222. //}
  223. //allprojects {
  224. // tasks.withType(JavaExec) {
  225. // enableAssertions = true // false by default
  226. // }
  227. // tasks.withType(Test) {
  228. // enableAssertions = true // true by default
  229. // }
  230. //}
  231. wrapper {
  232. gradleVersion = '5.6.4'
  233. }
  234. retrolambda {
  235. javaVersion JavaVersion.VERSION_1_7
  236. incremental true
  237. jvmArgs '-noverify'
  238. }