# Advanced composite build

**URL:** <https://discuss.gradle.org/t/advanced-composite-build/33379>\
**Category:** Help/Discuss\
**Created:** [October 1, 2019, 7:06am UTC](https://discuss.gradle.org/t/advanced-composite-build/33379 "2019-10-01T07:06:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![LaKz](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lakz/32/6955_2.png) [@LaKz](https://discuss.gradle.org/u/LaKz)\
**Post date:** [October 1, 2019, 7:06am UTC](https://discuss.gradle.org/t/advanced-composite-build/33379/1 "2019-10-01T07:06:51Z")

</div>

Hello everyone,

we have two projects _project1_ and _project2_. I uploaded an example to [Github](https://github.com/LarsKaulen/gradle-composite-build-example).

_project2_ has _project1_ as binary dependency:

```gradle
// project2 build.gradle
dependencies {
    implementation('com.example:project-1:1.0.0')
}

```

Now we want to include _project1_ as composite build in _project2_ which works just fine:

```gradle
// project2 settings.gradle
boolean substituteDependency = hasProperty('substituteDependency')

includeBuild('../project1') {
    if (substituteDependency) {
        dependencySubstitution {
            substitute module('com.example:project-1') with project(':')
        }
    }
}

```

Now we have some additional files in _project1_ which are placed in the distribution zip of _project1_ (represented by the **project1/src/main/dist/ExampleFile.txt** file). These files are needed in _project2_ for a specific task and therefore published together with the actual sources:

```gradle
// project1 build.gradle
publishing {
    publications {
        project1(MavenPublication) {
            artifactId = 'project-1'
            from components.java
            artifact(project.distZip) {
                classifier "resources"
            }
            artifact sourcesJar
            artifact javadocJar
        }
    }
}

```

```gradle
// project2 build.gradle
configurations {
    additionalResources
}
dependencies {
    additionalResources(group: 'com.example', name: 'project-1', version: '1.0.0', classifier: 'resources', ext: 'zip')
}
task exampleTask {
    inputs.files configurations.additionalResources.singleFile

    doLast {

        def tree = zipTree(configurations.additionalResources.singleFile)
        ...
    }
}

```

When using this setup together with the configuration as composite build we get the following error:

```gradle
A problem occurred evaluating root project 'project2'.
> Could not resolve all files for configuration ':additionalResources'.
   > Could not find project-1-resources.zip (project :project1).

```

Is there a possibility of substituting these additional resources with the outputs of _project1.distZip_ task? Or is there a different/better way to publish the additional resources in the first place?

Thanks for any advice.

---

<div class="post-metadata">

**Author:** ![LaKz](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lakz/32/6955_2.png) [@LaKz](https://discuss.gradle.org/u/LaKz)\
**Post date:** [June 9, 2020, 5:15pm UTC](https://discuss.gradle.org/t/advanced-composite-build/33379/2 "2020-06-09T17:15:51Z")

</div>

After this problem came up again, I had a close look at the features introduced with newer gradle versions (like `feature variants` and `capabilities`) and with help of the gradle team I managed to get my use case working. I updated the [example project](https://github.com/LarsKaulen/gradle-composite-build-example), but just in case - the main changes are as following:

```gradle
// project1 build.gradle
java {
    registerFeature('myFeature') { // add feature variant from main source set (in addition to the "default" feature)
        usingSourceSet(sourceSets.main)
    }
}

configurations.myFeatureApiElements.outgoing {
    artifacts.clear() // remove jar
    artifact distZip // add output of distZip task
}
configurations.myFeatureRuntimeElements.outgoing {
    artifacts.clear() // remove jar
    artifact distZip // add output of distZip task
}

```

```gradle
// project2 build.gradle
dependencies {
    additionalResources(group: 'com.example', name: 'project-1', version: '1.0.0') {
        capabilities { // use declared feature variant instead of "classifier"-extension
            requireCapability('com.example:project1-my-feature')
        }
    }
}

```
