GoogleContainerTools / GoogleContainerTools/jib
Custom Gradle source set added to main source set is absent from the image
- Dominant language
- Java
- Stars
- 14.5k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description
Hi 👋
**Environment**:
- *Jib version:* 3.3.0
- *Build tool:* Gradle 7.5.1
- *OS:* macOS Monterey 12.6
**Description of the issue**:
The `runtimeClasspath` of the main source set is incomplete.
Given I have two source sets in the same module (I excluded tests source sets):
- src/main/kotlin
- src/shared/kotlin
And I add the `shared` source set to the runtime classpath of the main one:
```kotlin
sourceSets {
val shared by creating
getByName("main") {
it.compileClasspath += shared.output
it.runtimeClasspath += shared.output
}
}
```
When I look into the image, I cannot see the classes from the `shared` source set. But when I run this custom task:
```kotlin
tasks.create("checkMainClasspath") {
doFirst {
println(sourceSets.getByName("main").runtimeClasspath.joinToString("\n") { it.toRelativeString(buildDir) })
}
}
```
I can see the expected output (truncated for conciseness):
```text
classes/java/main
classes/kotlin/main
resources/main
../../../../../../../.gradle/caches/modules-2/files-2.1/io.insert-koin/koin-ktor/3.2.2/e24cae73a4ad209ed5b57febed16b7a02b7ad423/koin-ktor-3.2.2.jar
[...]
../../../../../../../.gradle/caches/modules-2/files-2.1/io.zipkin.zipkin2/zipkin/2.23.2/1c2c7f2e91a3749311f7f75d0535d14ba2e2f6/zipkin-2.23.2.jar
classes/java/shared
classes/kotlin/shared
resources/shared
```
Also, the `jib-classpath-file` file does not reference this shared source set.
**Expected behavior**:
I would have expected the image to contain everything from the configuration used.
Nonetheless, it is possible to get around this by using the `extraDirectories` closure:
```kotlin
extraDirectories {
paths {
path {
setFrom("build/classes/kotlin/shared")
into = "/app/classes"
excludes.add("META-INF/*")
}
}
}
```
**Steps to reproduce**:
1. Add a custom source set to a Gradle module,
2. Add this source set's output to the main runtime classpath,
3. Add at least a class to this new source set,
4. Run `gradle jibBuildTar`,
5. Run `find build/jib-cache/layers -type f -print -exec tar -tvzf {} \;`
The file from the shared source set should be missing.
**`jib-gradle-plugin` Configuration**:
```kotlin
jib {
from {
image = "eclipse-temurin:17-jre"
platforms {
platform {
architecture = if (System.getProperty("os.arch") == "aarch64") "arm64" else "amd64"
os = "linux"
}
}
}
container {
jvmFlags = listOf("-XX:+UseZGC")
labels.put("APPLICATION_VERSION", project.version.toString())
}
}
```
**Additional Information**: I didn't try to reproduce it on a minimal Gradle project.
Regards.
Contributor guide
Assessment
This issue has not been assessed yet.