Set transitive=false for group of dependecies

Hi,

I have a list of >50 dependecies where I would like to disable transitive dependency resolution for all of them, but not for all others. Is there a way to that without specifying transitive=false 50 times?
I could easily identify them e.g. by name in a condition.

You could possibly do this

configurations {
   nonTransitive { transitive = false }
   implementation.extends nonTransitive
}
dependencies {
   nonTransitive 'a:b:1.0'
   nonTransitive 'c:d:1.1'
   nonTransitive 'e:f:1.2'
}

or perhaps

dependencies {
   ['a:b:1.0',  'c:d:1.1', 'e:f:1.2'].each {
      implementation(it) { transitive = false }
   }
}

Yes I tried that, but than nonTransitive is not in the implementation scope (not in my tests classpath). Is there an easy way to add nonTransitive to all implementation classpaths etc?

Edit: oh that last thing is a good idea.

Is there an easy way to add nonTransitive to all implementation

Please don’t do this… if need be you should create non-transitive configuration for each configuration you want to target.

eg:

configurations {
   apiNonTrans { transitive = false }
   implementationNonTrans { transitive = false }
   testImplementationNonTrans { transitive = false }

   api.extendsFrom apiNonTrans
   implementation.extendsFrom implementationNonTrans 
   testImplementation.extendsFrom testImplementationNonTrans
}
dependencies {
   apiNonTrans 'a:b:1.0'
   implementationNonTrans 'c:d:1.1'
   testImplementationNonTrans 'e:f:1.2'
}

Oh I initially tried the extendsFrom vice versa.

Still that way it also does not seem to work a:b:1.0 still seems to be resolved transitively.
I guess now the dependendencies from apiNonTrans end up in api where they are then resolved transitively?

I guess now the dependendencies from apiNonTrans end up in api where they are then resolved transitively

Yes, you’re quite likely correct… perhaps try my alternative approach

dependencies {
   ['a:b:1.0',  'c:d:1.1', 'e:f:1.2'].each {
      implementation(it) { transitive = false }
   }
}

Or maybe

dependencies {
   ext.implementationNonTrans = { dep -> implementation(dep) { transitive = false } }
   implementationNonTrans 'a:b:1.0'
   implementationNonTrans 'c:d:1.1'
   implementationNonTrans 'e:f:1.2'
}

Yes, that works. Even if its if its a little hackish, it should do it for the moment. Thank you!