https://kotlinlang.org logo
Title
x

x80486

07/06/2018, 3:43 AM
I'm trying to use it inside
subprojects { }
but so far is not letting me :trollface:
g

gildor

07/06/2018, 3:52 AM
It should work
subprojects {
  dependencies {}
}
Also you can apply dependencies to modules with specific plugin
x

x80486

07/06/2018, 3:59 AM
> Configure project :
Evaluating root project 'kotlin-akka2' using build file '/home/gorre/Workshop/Development/kotlin/kotlin-akka2/build.gradle.kts'.

FAILURE: Build failed with an exception.

* Where:
Build file '/home/gorre/Workshop/Development/kotlin/kotlin-akka2/build.gradle.kts' line: 30

* What went wrong:
Configuration with name 'compile' not found.
...and this is my "main" `build.gradle.kts`:
g

gildor

07/06/2018, 5:12 AM
this is because Gradle doesn’t know which configuration is available on your sub project and do not generated type safe accessor
compile
for you
use
"compile"("some:dep:1.2.3")
instead
it’s a way to add some dependency to particular configuration dynamically
x

x80486

07/07/2018, 12:19 AM
I have something working right now...but still, I can't do what I want, either in the way you propose it or without the double quotes...will play with that a little bit more
g

gildor

07/09/2018, 2:07 AM
What is your problem now?
x

x80486

07/09/2018, 2:08 AM
I mean, the same:
subprojects {
  dependencies {}
}
...I'm expecting that to work, so I don't have to repeat the same dependencies again and again on every subproject's build script
g

gildor

07/09/2018, 2:20 AM
Yes, and it works for many of my company projects and my personal projects
Maybe you could show same sample and explain what is not working for your
...basically, I'm trying to delete the
dependencies { ... }
block from `mod-*`'s
build.gradle.kts
and have that block only in
${root.project}/build.gradle.kts
I currently have the same setup in another Gradle project, but this one using Kotlin DSL just doesn't work so far...maybe I'm missing something
g

gildor

07/09/2018, 2:55 AM
I updated your build.gradle.kts I don’t see any problems to just move it to submodule block. as you can see I just extracted dependencies. I made a few other changes of config with my comments, but they are not related on dependencies sharing
sorry, forgot to commit changes of other files. Fixed, updated PR
as you can see each of your submodules have now only 1 line of config - description
Also, I do not want to say that problem of configuration of submodules doesn’t exist, there is big discussion about this. There is a few options, but because of dynamic nature of such config it’s not so straight forward.
x

x80486

07/09/2018, 3:13 AM
I didn't know 🙂 ...also, the quotes around the
"compile"
,
"testCompile"
, etc. is a required thing? That looks weird...like super weird. I hope that changes in the future...
Thanks for the changes! It works now! 😂👏
g

gildor

07/09/2018, 3:21 AM
It’s weird, because it’s dynamic, if you don’t like this syntax use desugared version:
add("compile", "your:dependency:1.2.3")
And yes, it’s required thing, as I mentioned on my first comment: https://kotlinlang.slack.com/archives/C19FD9681/p1530853992000059?thread_ts=1530848619.000148&cid=C19FD9681 https://kotlinlang.slack.com/archives/C19FD9681/p1530854016000033?thread_ts=1530848619.000148&cid=C19FD9681 Static accessor for configuration is not a global thing, different plugins provide different configurations, so kotlin-dsl do not allow you to use accessors that probably doesn’t exist for this module, because you apply configuration dynamically.
🤔 1
compile
is configuration of Kotlin plugin, and because you apply this plugin dynamically (on runtime of build), you have to use dynamic syntax, no type safe checks. Exactly the same happening in Groovy, but there Gradle handles all dynamic method calls To use static typed accessors you must use
plugins
dsl block, but unfortunately you cannot share this for multiple plugins