Groovy Gradle make Fat Jar


/ Published in: Groovy
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // make fat jar
  2. // exclude META-INF/MANIFEST.MF files and *groovy*.jar
  3.  
  4. def f_NotGroovyJar(ao) {
  5. // filter routine for find All to exclude groovy jar files
  6. def f_ew_jar = { a -> return a.toString().trim().toLowerCase().endsWith(".jar") }
  7. def f_has_groovy = { a -> return ( a.toString().trim().toLowerCase().contains("groovy") ) }
  8. return ( f_ew_jar(ao) ) && ( !f_has_groovy(ao) )
  9. }
  10.  
  11. jar {
  12. println "*** jar task beg ***"
  13. def cp1 = configurations.compile.collect { it }
  14. // note: might want to use configuration runtime instead for above line
  15.  
  16. def fo = new File( "${buildDir}/jars.txt" ).newWriter()
  17. cp1.each {
  18. fo.write( "${it.name}\n" )
  19. }
  20. fo.flush()
  21. fo.close()
  22.  
  23. def cp2 = cp1.clone().findAll { f_NotGroovyJar(it) }
  24. def classpath = cp2.collect { it.directory ? it : zipTree(it) }
  25.  
  26. from (classpath) {
  27. exclude 'META-INF/MANIFEST.MF'
  28. }
  29.  
  30. println "*** jar task end ***"
  31. // println "Press any key..."; System.in.read();
  32. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.