anschoewe wrote:
Hello,

I have a WAR project with several subproject that the WAR depends on.  When
I generate the WAR, I would like for the sub-project JARs to be bundled
inside the war.  However, all transitive and compile time dependencies
should be copied to an external folder/zip.

I'm curious why you want to do this?

Here's something that should do what you want (this is untested, but should give you some idea of how to solve the problem)

project(':Web Application') {
   task warLibs(type: Copy) {
       from { projectDependencies() }
       into "$buildDir/war/libs"
   }

   war {
       dependsOn warLibs
       additionalLibs(dir: "$buildDir/war/libs")
   }

   task otherJarsZip(type: Zip) {
       from { configurations.runtime.files - projectDependencies().files }
   }

   def projectDependencies() {
configurations.compile.copy { it instanceof ProjectDependency }.setTransitive(false)
   }

}


If we get round to revising the archive task API in 0.9, this will be a bit simpler (you won't need the copy for example)

  For example, suppose I have the
following:

/WebApplication
  /lib
/SubProjectA
  /lib
/SubProjectB
  /lib
/build.gradle
/settings.gradle

When I generate the WAR from the WebApplication, I would like the following
files produced:

webApplication.WAR.  It would contain
/lib/subProjectA.jar
/lib/subProjectB.jar

.... and a separate zip file would contain all of the other dependencies
(both compile-time and run-time for the WebApplication and each sub
project). Like

otherJars.zip
  /junit-addons-1.4.jar
  /xmlunit-1.2.jar
  /someJar-1.0.jar

My build.gradle currently looks something like this:

subprojects {
    usePlugin('java')
    version = '1.0'
    sourceCompatibility = 1.6
    targetCompatiblity = 1.6
}

/*
add the ability for the WAR to find all of the repositories of it's
sub-projects.  That way,
it can bundle all of the dependent runtime jars from the sub-projects
*/
allprojects { afterEvaluate { project -> project.configurations.each { config -> config.getDependencies(ProjectDependency.class).each {dep -> dep.dependencyProject.repositories.each {repos -> if (!project.repositories.all.contains(repos)) { project.repositories.add(repos) } } } } } }

project(":SubProjectA") {
        dependencies {
                compile name: 'junit-addons', version: '1.4'
                runtime group: 'xmlunit', name: 'xmlunit', version: '1.2'
        }
}

project(":SubProjectB") {
        dependencies {
                compile project(":SubProjectA")
                compile group: 'junit-addons', name: 'junit-addons', version: 
'1.4'
                runtime group: 'xmlunit', name: 'xmlunit', version: '1.2'
        }
}

project(":WebApplication") {
        usePlugin('war')
        dependencies {
                compile project(":SubProjectB")
                runtime name 'someJar', version: '1.0'
        }
}

-----------
I don't understand what task to intercept/override to perform this kind of
filtering.  My real project has more subprojects and dependent JARs. That's
why I programmatically find all dependent transitive jars 'afterEvaluate' is
called.

Any ideas?

Andrew

--
Adam Murdoch
Gradle Developer
http://www.gradle.org


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply via email to