How do I add exploded JAR content generated from another project inside the contents of the current project's JAR artifact?


(blackbeltdev) #1

I want to have two projects: one which generates static resources from GWT compiler and puts output into a JAR and a second project which consumes the JAR and places it’s content exploded into a new location within the second projects JAR.

I almost got it working but I’m getting the JAR file here and not the CONTENTS of the JAR file. I realize I need to use zipTree() but I can’t figure out the syntax (I included a second example ZIP file below that does roughly what I want that works):

Project A:

jar {
    from gwtCompile
}

Project B:

jar {
    dependsOn ":vaadin:VaadinWidgetset:gwtCompile", 'generateCss'
      into('META-INF/resources/VAADIN/widgetsets') {
        from project(':vaadin:VaadinWidgetset').jar.outputs.files
    }
    into('META-INF/resources') {
        from zipTree('lib/font-awesome-3.2.1.zip')
    }
}

I tried

from zipTree(project(':vaadin:VaadinWidgetset').jar.outputs.files.singleFile)

but that just results in:

The specified zip file ZIP ‘X:\workspaces\PQM\vaadin7\vaadin\VaadinWidgetset\build\libs\VaadinWidgetset-4.0.0-SNAPSHOT.jar’ does not exist and will be silently ignored. This behaviour has been deprecated and is scheduled to be removed in Gradle 2.0

Any ideas?

Thanks


(Peter Niederwieser) #2

One way to solve the problem is to wrap the expression in curly braces, to defer its evaluation until the ‘jar’ task runs, at which time the other Jar has already been produced (due to the task dependency). However, it isn’t recommended for one project to reach out into the object model of another project, because it leads to strong coupling, which causes problems like the above. Instead, I’d use a project dependency:

configurations {
    widgets
}
  dependencies {
    widgets project(':vaadin:VaadinWidgetset')
}
  jar {
    into('META-INF/resources/VAADIN/widgetsets') {
        from widgets
    }
}

With this solution, Gradle will also be able to infer the necessary task dependencies on its own.