# How to configure gradle dependency for tomcat lib folder?

**URL:** <https://discuss.gradle.org/t/how-to-configure-gradle-dependency-for-tomcat-lib-folder/45385>\
**Category:** Help/Discuss\
**Created:** [April 14, 2023, 6:06pm UTC](https://discuss.gradle.org/t/how-to-configure-gradle-dependency-for-tomcat-lib-folder/45385 "2023-04-14T18:06:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![i23098](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@i23098](https://discuss.gradle.org/u/i23098)\
**Post date:** [April 14, 2023, 6:06pm UTC](https://discuss.gradle.org/t/how-to-configure-gradle-dependency-for-tomcat-lib-folder/45385/1 "2023-04-14T18:06:50Z")

</div>

Hi have a multiproject where I want one of the libs to be in the tomcat lib folder (usually would be log4j or some other common lib). Code is available at [github](https://github.com/i23098/gradle8experiment), the dependencies in the build files are:

**regularLibA/build.gradle.kts**

```gradle
dependencies {
    implementation("org.apache.commons:commons-text:1.10.0")
}

```

**regularLibB/build.gradle.kts**

```gradle
dependencies {
    implementation("org.apache.commons:commons-lang3:3.12.0")
    implementation("org.apache.commons:commons-text:1.10.0")
}

```

**tomcatLib/build.gradle.kts**

```gradle
dependencies {
    implementation(project(":regularLibA"))
}

```

**webApp/build.gradle.kts**

```gradle
dependencies {
    implementation(project(":regularLibA"))
    implementation(project(":regularLibB"))
    implementation(project(":tomcatLib"))
}

```

The generated war file is:

```gradle
webApp.war
├── index.jsp
└── WEB-INF
    ├── classes
    │ └── com
    │ └── github
    │ └── i23098
    │ └── web
    │ └── W.class
    └── lib
        ├── commons-lang3-3.12.0.jar
        ├── commons-text-1.10.0.jar
        ├── regularLibA.jar
        ├── regularLibB.jar
        └── tomcatLib.jar

```

How to configure gradle so that tomcatLib project is to be in the tomcat lib folder, so, the jar and it’s dependencies should not be added to the war file? i.e. the generated war file should be:

```gradle
webApp.war
├── index.jsp
└── WEB-INF
    ├── classes
    │ └── com
    │ └── github
    │ └── i23098
    │ └── web
    │ └── W.class
    └── lib
        ├── commons-lang3-3.12.0.jar
        └── regularLibB.jar

```

I tried changing the `implementation(project(":tomcatLib"))` to `providedCompile(project(":tomcatLib"))` in `webApp/build.gradle.kts` but for some reason gradle doesn’t add `commons-lang3-3.12.0.jar` in that case.

Also, how to create copy task of the files that are excluded from the war (tomcatLib.jar, regularLibA.jar and commons-text-1.10.0.jar) into the tomcat lib folder?

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [April 15, 2023, 5:55pm UTC](https://discuss.gradle.org/t/how-to-configure-gradle-dependency-for-tomcat-lib-folder/45385/2 "2023-04-15T17:55:40Z")

</div>

`providedCompile` is exactly the way to go. It is available at compile time but otherwise provided by the container.

As `commons-text` depends on `commons-lang3` and you declared that `:tomcatLib` and all its transitive dependencies are provided by the container, also `commons-lang3` is not packaged into the war.

For the last question, well, just do it, what problem do you have with it?

---

<div class="post-metadata">

**Author:** ![i23098](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@i23098](https://discuss.gradle.org/u/i23098)\
**Post date:** [April 15, 2023, 6:21pm UTC](https://discuss.gradle.org/t/how-to-configure-gradle-dependency-for-tomcat-lib-folder/45385/3 "2023-04-15T18:21:29Z")

</div>

> [@Vampire](#):
>
> As `commons-text` depends on `commons-lang3` and you declared that `:tomcatLib` and all its transitive dependencies are provided by the container, also `commons-lang3` is not packaged into the war.

I picked some random common libs, did not notice they had dependency between them. Then it makes sense 🙂

> [@Vampire](#):
>
> For the last question, well, just do it, what problem do you have with it?

I don’t know how to do it 😕 How do I dynamically get the list of files (the generated `tomcatLib.jar` and transitive `regularLibA.jar` from the subprojects as well as their dependencies `commons-lang3-3.12.0.jar` and `commons-text-1.10.0.jar`) to put in the `from` of the `Copy` task?

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [April 15, 2023, 11:10pm UTC](https://discuss.gradle.org/t/how-to-configure-gradle-dependency-for-tomcat-lib-folder/45385/4 "2023-04-15T23:10:52Z")

</div>

```plaintext
val foo by tasks.registering(Copy::class) {
    from(configurations.providedRuntime)
    into(...)
}

```

---

<div class="post-metadata">

**Author:** ![i23098](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@i23098](https://discuss.gradle.org/u/i23098)\
**Post date:** [April 16, 2023, 8:40am UTC](https://discuss.gradle.org/t/how-to-configure-gradle-dependency-for-tomcat-lib-folder/45385/5 "2023-04-16T08:40:05Z")

</div>

Thanks for you help. It worked 🙂
