Composite Builds and an Ear Project

Hi, i’m having an issue with a composite build that includes a project using the ear plugin. i created a sample project to show the issue. it looks like:

ear-composite
├── gradle-java-ear
│   ├── build.gradle
│   └── settings.gradle
└── test
    ├── build.gradle.kts
    ├── gradle
    │   └── wrapper
    │       ├── gradle-wrapper.jar
    │       └── gradle-wrapper.properties
    ├── gradlew
    ├── gradlew.bat
    └── settings.gradle.kts

the test project includes the gradle-java-ear project and the build file looks like:

plugins {
    base
}

val ears by configurations.creating

configurations.all {
    isTransitive = false
}

dependencies {
    ears("org.test:gradle-java-ear")
}

tasks.register<Copy>("fetchDeployments") {
    into(layout.buildDirectory.dir("deployments"))
    from(ears)
}

when running gradle fetchDeployments, i get the following error:

Could not determine the dependencies of task ':fetchDeployments'.
> Could not resolve all task dependencies for configuration ':ears'.
   > Could not resolve org.test:gradle-java-ear.
     Required by:
         project :
      > Cannot choose between the following variants of project :gradle-java-ear:
          - deploy
          - earlib
        All of them match the consumer attributes:
          - Variant 'deploy' capability org.test:gradle-java-ear:unspecified:
              - Unmatched attributes:
                  - Provides org.gradle.category 'library' but the consumer didn't ask for it
                  - Provides org.gradle.dependency.bundling 'external' but the consumer didn't ask for it
                  - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
          - Variant 'earlib' capability org.test:gradle-java-ear:unspecified:
              - Unmatched attributes:
                  - Provides org.gradle.category 'library' but the consumer didn't ask for it
                  - Provides org.gradle.dependency.bundling 'external' but the consumer didn't ask for it
                  - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it

Any ideas on what i’m missing? I’ve uploaded the test project.

ear-composite.zip (64.7 KB)

If you look at WAR/EAR plugins - Add consumable configuration for WAR (aka outgoing variant) · Issue #1353 · gradle/gradle · GitHub, you see neither the war, nor the ear plugin have proper outgoing variants you could consume like that.

If you also control the ear project, you need to define a proper outgoing variant, that you can then consume downstream.

You can also abuse for example the java plugin for that, by applying the java project additionally in your ear project and adding

configurations {
    runtimeElements.outgoing.artifacts.clear()
    runtimeElements.outgoing.artifact(tasks.named('ear'))
}

and suddenly your consumer works as intended. :slight_smile:

Thanks so much for that!!

1 Like