https://kotlinlang.org logo
#intellij
Title
# intellij
k

karelpeeters

09/25/2019, 11:25 AM
I'm trying to add a third sourceset/module, similar to
main
and
test
but called
local
. I want it to depend on both
main
and
test
. This is my build.gradle: https://pastebin.com/raw/5u89DqYP, building with gradle commandline seems to work so i think that's correct. I'm having some problems getting it to work in intelij though, when I change any code in eg. the
main
module I start to get build errors like this:
m

Mike

09/25/2019, 11:33 AM
I'll assume you're delegating Intellij builds/tests to Gradle, but just in case, I'll ask.
k

karelpeeters

09/25/2019, 12:08 PM
Yeah I do, sorry for not mentioning that. It's really, strange, it should just be the same right?
m

Mike

09/25/2019, 12:15 PM
Agreed. It's supposed to be... Not sure how adding local is affecting test compilation. Behind firewall so can't access pastebin right now. Will look at build.gradle when I can
k

karelpeeters

09/25/2019, 12:29 PM
m

Mike

09/25/2019, 1:06 PM
Used to be able to, but now it enforces HTST, and our proxy messes with certs... Frustrating. I'm WFH today, so can see it as I dropped off VPN.
Hmm. Take a look at how they define a sourceSet/configuration here: https://docs.gradle.org/current/userguide/java_testing.html#sec:configuring_java_integration_tests Consider just extending
test
rather than explicitly adding both
main
and
test
to local. The example adds main, but that's because they explicitly DON'T want it to extend/know about test code. The sourceSet defines the code dependencies, and the Configuration defines the dependency hierarchy. I don't think you need the configuration unless you want to be able to add dependencies only for local. Cleaner build config. I'm not sure how new Gradle has to be for this to work, but I think it's been this way since late 4, and hopefully you're on 5.
I'm also curious why you point java, kotlin and resources all at the same directory? Don't like the
main/java
,
main/kotlin
and
main/resources
approach? At least I think that's what happens when you set it to
src/main
, isn't it?
k

karelpeeters

09/25/2019, 1:28 PM
Hmm trying what they're doing in that example, ie. just adding the output only causes intelij to not even find the stdlb anymore. What do you mean by "extending test"? How do you do that? I'm on Gradle 5.6 so that should all be fine 🙂 I don't like the separate source and resource folders, it probably makes sense if you have actual separate resources but for me classes and the resources are tightly coupled, it's just a duplicate package hierarchy so I might as well put them next to each other. I'll read the entire page you linked more carefully in a couple of hours, thank you for the help already!
m

Mike

09/25/2019, 1:36 PM
Extending test by replacing the
+= sourceSets.main.output
with
+= sourceSets.test.output
in the example. Yes, of course. It can't find stdlib because I was wrong. The
configurations
block is required. Have to tell Gradle what dependencies belong in
localImplementation
. In your case, you again want to extend test, so instead of
implementation
, you'd put
testImplementation
and
testRuntimeOnly
. Functionally, this is basically what you had, but perhaps IntelliJ will import this correctly, and you won't have errors. And it's the approach currently recommended by Gradle, so may as well use it. The one thing I don't like about Gradle. If you've been working with it awhile, there have been many different ways to define things. And if you're new, you're just as likely to find one of the 'old' ways as you are to find the 'new' way. HTH. Good luck!
3 Views