Excluding Jar/Dependent Project from WAR, but keep transitive deps intact

I haven’t come across a solution for this after an extensive search, so thought I would pose the question to this forum.

I have a need to exclude a project artifact in a multi-project build. If I I have the layout

Project A - Jar file Project B - War file, depends on Project A for compile

But the Jar from Project A will be deployed to a tomcat common folder, is it possible to exclude Project A’s jar from Project B, but keep all the transitive dependencies in the WAR file?

I’m tempted to ant.unzip to a directory, delete the Project A jar, and zip it up again, but don’t know if there is a more elegant way before I go that route

Unless I miss-understood you question…

The ‘classpath’ property of war determines what is included in the WAR archive.

http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.bundling.War.html#org.gradle.api.tasks.bundling.War:classpath

You may exclude the ProjectA jar from the class path with the following configuration:

war {
    classpath = classpath.filter {File file ->
        return !("ProjectA.jar".equals(file.name))
    }
}

Ah, that’s perfect, I’ll give that a try.

Hmm, that doesn’t seem to have the desired effect. I tried using a println statement to see what the classpath is, but even when logging in info level (-i command line arg), I did not get a printout of the classpath to see what was happening.

I’ll keep investigating, any suggestions?

After fixing my build.gradle this worked perfectly, thanks!