How can I depend on the war created in a different...
# community-support
n
How can I depend on the war created in a different module? I see the plugin creates a variant in the
archives
configuration, but I can't seem to resolve that from a different module 🤔
Copy code
--------------------------------------------------
Variant archives
--------------------------------------------------
Configuration for archive artifacts.

Capabilities
    - com.acme:web-module:0.0.0 (default capability)
Artifacts
    - build/libs/web-module-0.0.0.jar (artifactType = jar)
    - build/libs/web-module-0.0.0.war (artifactType = war)
I tried
Copy code
implementation(projects.webModule) { artifact { type = "war" } }
or
implementation(projects.webModule) { artifact { extension = "war" } }
but neither worked resulting in
Copy code
Could not find web-module.war (project :web-module).
According to the documentation, the
war
plugin creates a new
components.web
component, but I'm not sure how to depend on/resolve that.
1
v
The war plugin does not create an outgoing variant that provides the
war
unfortunately, neither does the
ear
plugin. See https://github.com/gradle/gradle/issues/1353 and https://github.com/gradle/gradle/issues/34192 for reference. What I do in such cases is to modify the default outgoing variants to include the
war
instead of the
jar
. This works properly as long as the project does not produce a
jar
that should also be consumed by other projects, but only the
war
. So for example
Copy code
val apiElements by configurations.existing {
    outgoing.artifacts.clear()
    outgoing.artifact(war)
    attributes {
        attribute(BUNDLING_ATTRIBUTE, objects.named(EMBEDDED))
    }
}

val runtimeElements by configurations.existing {
    outgoing.artifacts.clear()
    outgoing.artifact(war)
    attributes {
        attribute(BUNDLING_ATTRIBUTE, objects.named(EMBEDDED))
    }
}
This removes the
jar
from the two outgoing variants and adds the
war
instead. Then you can just depend on the project that produces the
war
and you get the
war
as artifact. The
archives
configuration is not something you should or can consume by default and iirc in recent Gradle versions also does not exist anymore. It was iirc mainly defining which artifacts get built if you use the
assemble
task.
n
nice, thank you 👍
👌 1