Jolan Rensen [JetBrains]
07/04/2022, 1:50 PMsrc/main/kotlin
, making IntelliJ stop giving hints. Is there a way to change the sourcesets in gradle while keeping the source root markings of IntelliJ as they were?
I have a sample project (actually built for something else) which has this issue. I marked it in TODOs for instance here. I did an attempt with idea.module {}
in build.gradle.kts
but that didn't seem to do anything except from giving me duplicate content roots... Any tips?
I was personally thinking I could maybe set the source folders back after building/deploying or something , but I also couldn't figure out how to do that...Oliver.O
07/04/2022, 2:20 PMsetSrcDirs
, erasing the main source directory. Would it work if you'd just add a source directory like so?
kotlin {
sourceSets {
main {
kotlin.srcDir(preprocessMain.target.get())
}
}
}
Jolan Rensen [JetBrains]
07/04/2022, 2:23 PMOliver.O
07/04/2022, 2:26 PMJolan Rensen [JetBrains]
07/04/2022, 2:28 PMOliver.O
07/04/2022, 2:31 PMJolan Rensen [JetBrains]
07/04/2022, 2:31 PMidea.module {}
should be able to help, but I didn't manage to configure that to solve my issueOliver.O
07/04/2022, 2:36 PMJolan Rensen [JetBrains]
07/04/2022, 2:39 PMOliver.O
07/04/2022, 2:53 PMidea
plugin, from what I've read, would the whenMerged
hook help in this case?Jolan Rensen [JetBrains]
07/04/2022, 3:00 PMOliver.O
07/04/2022, 3:13 PMJolan Rensen [JetBrains]
07/04/2022, 3:18 PMOliver.O
07/04/2022, 3:35 PMbeforeMerged
and whenMerged
hooks don't get called. :blob-shrug:Jolan Rensen [JetBrains]
07/04/2022, 3:35 PMOliver.O
07/04/2022, 3:38 PMThe techniques we discuss in this section don’t work with IDEA’s import facility
Jolan Rensen [JetBrains]
07/04/2022, 3:38 PMval kotlinMainSources = kotlin.sourceSets.main.get().kotlin.sourceDirectories
val preprocessMain by tasks.creating(JcpTask::class) {
sources.set(kotlinMainSources)
clearTarget.set(true)
fileExtensions.set(listOf("kt"))
vars.set(Versions.versionMap)
outputs.upToDateWhen { false }
}
tasks.compileKotlin {
dependsOn(preprocessMain)
doFirst {
kotlin {
sourceSets {
main {
kotlin.setSrcDirs(listOf(preprocessMain.target.get()))
}
}
}
}
doLast {
kotlin {
sourceSets {
main {
kotlin.setSrcDirs(kotlinMainSources)
}
}
}
}
}
Oliver.O
07/05/2022, 2:28 PMJolan Rensen [JetBrains]
07/05/2022, 2:28 PMOliver.O
07/05/2022, 2:32 PMJolan Rensen [JetBrains]
07/05/2022, 2:37 PMDayTimeIntervalType()
just doesn't yet exist before spark 3.2, so I cannot reference it using a normal if-statement, it needs to be actually removed from the code. Same story if you'd want to autogenerate it, it's a 1400+ lines file...tasks.compileKotlin {
dependsOn(preprocessMain)
outputs.upToDateWhen { false }
}
seems do do something!Oliver.O
07/05/2022, 3:10 PMJolan Rensen [JetBrains]
07/05/2022, 3:15 PMpreprocessMain.outputs.upToDateSpec(this)
and in preprocessedMain I'm trying to create a file listener or something, so that the preprocessing detects correctly it's time to runOliver.O
07/05/2022, 3:21 PMJolan Rensen [JetBrains]
07/05/2022, 3:22 PMOliver.O
07/05/2022, 3:24 PMJolan Rensen [JetBrains]
07/05/2022, 3:25 PMtasks.compileKotlin {
dependsOn(preprocessMain)
outputs.upToDateWhen { preprocessMain.outcomingFiles.files.isEmpty() }
}
seems to do the trick. JCP has outcoming files when there were changes anywhere in your given source folders. IntelliJ also always listens to upToDateWhen 🙂