java - Write Compile Time Dependencies to a File -


i'm trying go through dependencies of project , write in custom file.

i'm familiar way create fat jar, using 'jar' plugin, similar approach in custom task seems not work.

some of code i've tried.

// first way tried it.  task customtask(){     file manifest = new file('file.txt')     manifest << 'some text\n'     manifest << 'dependencies:'      configurations.runtime.collect{ manifest << it.name}  }  // second way tried it.  task manifest(){     file manifest = new file('file.txt')     manifest << 'header\n'     manifest << 'dependencies:'     filetree tree = filetree(dir: configurations.compile, include: '**/*.jar')     tree.each {file file ->         manifest << file     }  } 

the configuration object returned configuration.runtime filecollection interface, can readily iterate on it. why filetree(dir: xxx) didn't work, takes directory path , creates list of files, configuration one.

the following worked me:

apply plugin: 'groovy' dependencies {     // compile gradleapi()     compile 'junit:junit:4.11' }  repositories {     mavencentral() }  task t1 << {     def manifest = project.file('file.txt')     manifest.delete()     manifest << 'dependencies:\n'      // can use it.path here if need full path jar     configurations.runtime.each { manifest << it.name + "\n"}      // configurations.compile.each works here } 

it output following:

dependencies: junit-4.11.jar hamcrest-core-1.3.jar 

uncommenting line compile groovyapi() in dependencies, , pulls lot more jars in.

generally use project.file() (you can use file() verbose on project methods) creating file objects, rather new file(foo).

as suggested peter ledbrook in comments below, there further optimisations task, particularly around making file output of task, if inputs of task haven't changed, file doesn't need recreated, , job skip. above raw.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -