Slackbot
07/11/2022, 4:52 PMmelix
07/11/2022, 4:57 PMafterEvaluate, so potentially, your code executes before. In practice it's unlikely.Ben Madore
07/11/2022, 4:58 PMmelix
07/11/2022, 5:01 PMFleshgrinder
07/11/2022, 5:05 PM// do thing
project.withPlugin("org.springframework.boot") {
// undo thing
}melix
07/11/2022, 5:06 PMmelix
07/11/2022, 5:06 PMFleshgrinder
07/11/2022, 5:07 PMBen Madore
07/11/2022, 5:08 PMBen Madore
07/11/2022, 5:10 PMBen Madore
07/11/2022, 5:11 PMif(module isn't executable - i.e. doesn't have spring boot plugin applied) {
exclude a bunch of logging implementations
}
seems like afterEvaluate is the best optionmelix
07/11/2022, 5:11 PMmelix
07/11/2022, 5:11 PMmelix
07/11/2022, 5:11 PMmelix
07/11/2022, 5:12 PMFleshgrinder
07/11/2022, 5:12 PMlibrary and application plugin. The library plugin does what you want, the application plugin does not.melix
07/11/2022, 5:12 PMmelix
07/11/2022, 5:12 PMFleshgrinder
07/11/2022, 5:13 PMtony
07/11/2022, 5:16 PMBen Madore
07/11/2022, 5:45 PMBen Madore
07/11/2022, 5:51 PMdependency {
...
implementation "ch.qos.logback:logback-core"
...
}
i want to force this to be excluded by applying my plugin which has:
dependencies {
// Exclude any logging implementations from being exposed by library as they can break consumers
configurations.runtimeOnly {
...
exclude(group = "ch.qos.logback", module = "logback-core")
...
}
}
this seems to work for gradle consumers, but the generated maven pom looks like:
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<scope>runtime</scope>
<exclusions>
<exclusion>
<artifactId>logback-core</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
</exclusions>
</dependency>
which… doesn’t actually remove it from a maven consumer.Ben Madore
07/11/2022, 5:53 PMBen Madore
07/11/2022, 6:03 PMslf4j-api.Ben Madore
07/11/2022, 6:05 PMFleshgrinder
07/11/2022, 6:19 PMconfigurations.runtimeOnly {
resolutionStrategy.eachDependency {
if (requested.group == "ch.qos.logback" && requested.name == "logback-core") {
error("no no")
}
}
}
That said, to filter things out from the POM you'd actually want to hook into the maven-publish plugin and filter them out there. Coincidently this would solve your library vs application problem as well, because I would assume that nobody packages their applications in form of JARs and uploads them to a Maven repository. 😛Ben Madore
07/11/2022, 6:21 PMBen Madore
07/11/2022, 6:44 PMconfigurations.all it fails. but that’s not what i want, i want to be able to have these deps in the test runtimeFleshgrinder
07/11/2022, 7:13 PMruntimeOnly in my example code because it was the one you used in your example code. If you want to capture dependencies introduced by any main dependency (implementation, api, and runtimeOnly) then use `runtimeClasspath`:
configurations.runtimeClasspath {
resolutionStrategy.eachDependency {
if (requested.group == "ch.qos.logback" && requested.name == "logback-core") {
error("no no")
}
}
}
This will always trigger when the dependencies are resolved.Fleshgrinder
07/11/2022, 7:17 PMVampire
07/11/2022, 7:37 PMdependencies task?
The latter does lenient resolving where only failed is printed.
If you actually try to build, it should fail if I'm not mistaken.Fleshgrinder
07/11/2022, 7:40 PMBen Madore
07/11/2022, 7:40 PMdependencies {
configurations.runtimeClasspath {
val configName = this.name
dependencies.configureEach {
if (isBannedLoggingImpl(this)) {
throw GradleException(
"""Logging Implementations must NOT be added to the runtime classpath of shared library modules.
|Please remove dependency declaration on: $configName("${this.group}:${this.name}")
""".trimMargin()
)
}
}
}
}
and in the consuming project:
implementation "ch.qos.logback:logback-core"
api "ch.qos.logback:logback-core"
runtimeOnly "ch.qos.logback:logback-core"
all of which i’d expect to fail. but building it doesn’t, it works fine.
if i change the plugin to configurations.all it does fail.Vampire
07/11/2022, 7:41 PMafterEvaluate and presence check, you might additionally add a withPlugin for the absent plugin that throws an exception, so that the build fails if the plugin in question is applied in a later afterEvaluate.Ben Madore
07/11/2022, 7:41 PMBen Madore
07/11/2022, 7:43 PMconfigurations.all {
val configName = this.name
// We can allow logging impls for any test configurations
if (!configName.contains("test")) {
dependencies.configureEach {
if (isBannedLoggingImpl(this)) {
throw GradleException(
"""GD Error: Logging Implementations must NOT be added to the runtime classpath of shared library modules.
|Please remove dependency declaration on: $configName("${this.group}:${this.name}")
""".trimMargin()
)
}
}
}
}
it’s pretty janky, specifically the skipping based on “test” being in the configuration name (but i do need to make sure logging impl libs can show up at test time)