init.gradle 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. allprojects { everyProj ->
  2. task printClasspath {
  3. doLast {
  4. def classPath = [].toSet();
  5. pluginManager.withPlugin('java') {
  6. classPath = sourceSets.main.runtimeClasspath.asPath
  7. }
  8. if (!classPath) {
  9. pluginManager.withPlugin('android') {
  10. def androidBootClasspath = android.getBootClasspath()[0]
  11. def cp = [androidBootClasspath];
  12. def confAttrSpec = [:]
  13. def configuredDimensionList = []
  14. if (project.hasProperty('confAttrs')) {
  15. confAttrSpec = confAttrs.toLowerCase().split(',').collectEntries { [(it.split(':')[0]) : it.split(':')[1]] }
  16. configuredDimensionList = android.flavorDimensionList.findAll { confAttrSpec[it] }
  17. }
  18. project.android.applicationVariants.all { v ->
  19. // remove classpath for unused buildTypes
  20. if (confAttrSpec['buildtype'] && v.buildType.getName() != confAttrSpec['buildtype']) {
  21. return
  22. }
  23. // remove classpath for unused dimensions
  24. if (configuredDimensionList) {
  25. def usedFlavors = configuredDimensionList.findAll {
  26. v.flavorName.toLowerCase() == confAttrSpec[it]
  27. }
  28. if (!usedFlavors) {
  29. return;
  30. }
  31. }
  32. v.getCompileClasspath(null).getFiles().each {
  33. File f ->
  34. cp.add(f.getAbsolutePath())
  35. }
  36. v.javaCompile.classpath.getFiles().each {
  37. f -> cp.add(f)
  38. }
  39. cp.add(v.javaCompile.destinationDir.getAbsolutePath())
  40. }
  41. classPath = cp.join(":")
  42. }
  43. }
  44. /*
  45. the `snykReachabilityClasspath` can be declared using a `ext` block
  46. in the projects build script
  47. e.g for java:
  48. ext {
  49. snykReachabilityClasspath = sourceSets.main.compileClasspath.asPath
  50. }
  51. It requires a path formatted string, e.g:
  52. */
  53. if (!classPath && project.hasProperty('snykReachabilityClasspath')) {
  54. classPath = project.snykReachabilityClasspath
  55. }
  56. if (classPath) println(classPath)
  57. }
  58. }
  59. }