GoogleContainerTools / GoogleContainerTools/jib
Collect all output of a Gradle's SourceSetOutput.getDirs()
- Dominant language
- Java
- Stars
- 14.5k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Environment**:
- *Jib version: 3.2.1
- *Build tool:* Gradle 7.4.0
- *OS:* Windows
**Description of the issue**:
A gradle sourceSet has a common output as sourceSets.main.output
When an additional output directory is registered to the main source set then it should be part of the created image.
**Expected behavior**:
the contents of $buildDir/generated/extraResources/ to be added to the jib image.
**Steps to reproduce**:
```groovy
def generatorTask = tasks.register("generateExtraResources") {
outputs.dir("$buildDir/generated/extraResources")
doLast {
file("$buildDir/generated/extraResources/some-file.properties").write "Hello"
}
}
// the directory "$buildDir/generated/extraResources" is now registered as part of the output of the sourceset and would be added to the jar of a java project.
sourceSets.main.output.dir(generatorTask)
```
**Log output**:
**Additional Information**:
The issue seems to be the code here:
https://github.com/GoogleContainerTools/jib/blob/86a3c855cb302da7671356dad7d2559fe3f138f5/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleProjectProperties.java#L223
// current code
```java
SourceSet mainSourceSet = getMainSourceSet();
FileCollection classesOutputDirectories =
mainSourceSet.getOutput().getClassesDirs().filter(File::exists);
Path resourcesOutputDirectory = mainSourceSet.getOutput().getResourcesDir().toPath();
FileCollection allFiles =
project.getConfigurations().getByName(configurationName).filter(File::exists);
...
switch (containerizingMode) {
case EXPLODED:
// Adds resource files
if (Files.exists(resourcesOutputDirectory)) {
javaContainerBuilder.addResources(resourcesOutputDirectory);
}
...
```
// perhaps better approach
```java
SourceSet mainSourceSet = getMainSourceSet();
FileCollection classesOutputDirectories =
mainSourceSet.getOutput().getClassesDirs().filter(File::exists);
FileCollection resourcesOutputDirectories = mainSourceSet.getOutput().minus(mainSourceSet.getClassesDirs()).filter(File::exists);
...
switch (containerizingMode) {
case EXPLODED:
// Adds resource files
for (File resourcesOutputDirectory: resourcesOutputDirectories) {
javaContainerBuilder.addResources(resourcesOutputDirectory.toPath());
}
...
```
mainSourceSet.getOutput() is a fileCollection by itself so the split is only relevant to get the two separate directories classes and resources in the image.
Contributor guide
Assessment
This issue has not been assessed yet.