How to define second settings.gradle

End goal is build two jars, one with just the application*.yml files and the other the application files and dependent jars without the application*yml files.

When I initially defined

jar {
  processResources.exclude('application*.yml')
}

The (SpringBootTests) tests started failing where they were expecting the property files and they were not present.

Looked everywhere, but couldn’t find a solution, so came up with a separate build.gradle (release.gradle) to do this. All good, except, by design apparently, the --build-file=release.gradle ignores the settings.gradle and I loose the rootProject.name assignment. My CI pipeline now fails to find the jar files.

I tried amending release.build to be

jar {
  archiveBaseName = 'ciExpectedName'
  processResources.exclude('application*.yml')
}

and then

jar {
  processResources.exclude('application*.yml')
}
assemble {
    jar.archiveBaseName = 'ciExpectedName'
}

Application archive name still wrong.

This DOES work - but ONLY for the resources.

task resourcesJar(type: Jar) {
    archiveBaseName = 'ciExpectedName'
    archiveClassifier = 'resources'
    from sourceSets.main.resources

    include('application*.yml')

    dependsOn configurations.runtimeClasspath
}

I tried to then add --settings-file=settings.gradle to be informed

Sorry if this is a newbie question, but I have searched everywhere to no avail. I have the following setup
build.parent.gradle
build.gradle
release.gradle
settings.gradle
src\main\java
src\main\resources
src\test\java
src\test\resources\

Using gradlew; and I think the version is 6.6

Hope someone can assist!
Cheers… Andrew

The jar task has no processResources property. The above code is actually configuring the processResources task and is equivalent to:

jar {
}
processResources.exclude( ... )

To apply an exclude to the jar task, use jar.exclude(...) instead.

jar {
    exclude('qpplication*.yml')
}
1 Like

Thanks for your quick response Chris.

Tried as you recommended, and while the testing is now fixed, the assembly into the final jar is not, exclude(…) does not seem to work :frowning: for /in the jar creation.
Initial attempt was

jar {
    exclude('application*.yml', 'myApp-keystore.jks', 'myApp-truststore.jks')
}

simplifed to

jar {
    exclude('application.yml')
}

Then, based on different online reading suggestions, tried a few different variants, from ‘**/application*.yml’ to ‘BOOT-INF/classes/application*.yml’ to naming each file individually; tried using single and double quotes.
This was my last failed attempt

jar {
    exclude('application.yml', '**/application.yml', 'BOOT-INF/classes/application.yml')
    exclude("application.yml", "**/application.yml", "BOOT-INF/classes/application.yml")
    exclude 'application.yml', '**/application.yml', 'BOOT-INF/classes/application.yml'
    exclude "application.yml", "**/application.yml", "BOOT-INF/classes/application.yml"
    exclude('application.yml')
    exclude('**/application.yml')
    exclude('BOOT-INF/classes/application.yml')
    exclude('**/BOOT-INF/classes/application.yml')
}

File is still present in the jar…

Command being used ./gradlew clean assemble --rerun-tasks

Nothing seems to work - the files are never excluded. More searching and almost all the resolutions are to move the files to other locations which is not feasible. These are valid files for an appropriate environment (dev, qa, prod); just their provisioning is via a ConfigMap, not included in the application distribution.

Any thoughts on why its not excluding the files?
Thanks!