thought maybe I could create a dependency constrai...
# community-support
c
thought maybe I could create a dependency constraint for all valid matching configurations. Tried this, but it has an error (also tried using a string with
.create
same error)
Copy code
val jbossLoggingConstraint = dependencies.constraints.create(libs.jboss.logging)

configurations.matching {
  !setOf(
    "archives",
    "default",
  ).contains(it.name) && !it.name.contains("Elements") && !it.name.endsWith("Classpath")
}
  .configureEach {
    this.dependencyConstraints.add(jbossLoggingConstraint)
  }
Copy code
* Where:
Build file '/home/xeno/IdeaProjects/spring-app-commons/module/app-core/build.gradle.kts' line: 6

* What went wrong:
An exception occurred applying plugin request [id: 'our.javalibrary']
> Failed to apply plugin 'our.bom'.
   > Cannot convert the provided notation to an object of type DependencyConstraint: map(valueof(DependencyValueSource)).
     The following types/formats are supported:
       - Instances of DependencyConstraint.
       - String or CharSequence values, for example 'org.gradle:gradle-core:1.0'.
       - Maps, for example [group: 'org.gradle', name: 'gradle-core', version: '1.0'].
       - Projects, for example project(':some:project:path').
       - Instances of ProjectDependency.
     
     Comprehensive documentation on dependency notations is available in DSL reference for DependencyConstraintHandler type.
s
I think you need to call get() on libs.jboss.logging. Version catalog accessors usually return a provider and a provider is not in the list of accepted notations.
c
there actually is a version that accepts a provider, tried that too, but like I said, also tried the stringy version
and got the same error
v
How about
Copy code
configurations.matching {
    !setOf(
        "archives",
        "default",
    ).contains(it.name) && !it.name.contains("Elements") && !it.name.endsWith("Classpath")
}
    .configureEach {
        dependencies {
            constraints {
                this@configureEach(libs.jboss.logging)
            }
        }
    }
?
c
looks like that works. btw, is there a more efficient way to do the matching part? is there something other than matching name that I can do?
Copy code
.matching {
    !setOf(
      "archives",
      "default",
    ).contains(it.name) &&
      !it.name.endsWith("Classpath") &&
      !it.name.contains("Elements")
  }
v
Well, maybe you should not create a new set to use contains for each and every matched configuration. Either pull the set creation out of the
matching
or just use two
==
checks and an
&&
instead. Other than that, I don't know whether there is a better way, as I don't know what your goal is. If your goal is, to match all configurations that are not named
archives
, not named
default
, not name ends with
Classpath
, and not name contains
Elements
, well, then that is your check. I just don't see much logic in that condition, but if that is your use-case, ... 🙂
c
those caused errors 😉 it wouldn't let me operate on configurations matching those names 😉
I had an entirely different set of errors the first time around
it.name seemed like the only thing to match, and I made a set because I thought it was going to be a lot, but then endsWith and contains seemed shorter and I just never removed the set
v
As I said, using a set is also find, but by having it within
matching
you create a new set for each and ever tested configuration.
c
honestly, doesn't look like that error comes up with the way you write the code, so, pretty certain I can just remove that 😉
👌 1