My build.gradle.kts seems to break whenever IDEA is upgraded
Is there some non-obvious way of getting a build.gradle.kts which doesn’t regularly break when IDEA is updated? I have a project which happens to have a non-standard source layout:
my-kotlin-library
├── build.gradle.kts
└── src
├── main
│ └── MyLibrary.kt
└── test
└── MyLibraryTest.kt
Since I only have Kotlin sources, it makes no sense (to me) to have the more conventional layout with an inserted “kotlin” subdirectory:
my-kotlin-library
├── build.gradle.kts
└── src
├── main
│ └── kotlin
│ └── MyLibrary.kt
└── test
└── kotlin
└── MyLibraryTest.kt
Anyway, my unconventional setup was working fine, and I had a working run configuration which found and ran all my tests … after some weeks, I upgraded IDEA (to 2019.2, I think), along with the plugins I was told were outdated. After this, my tests weren’t found any more! To solve this, I had to add
sourceSets {
main {
java {
srcDir("src/main")
}
}
test {
java {
srcDir("src/test")
}
}
}
to my build.gradle.kts, and my tests were found again! I’ve no idea why it worked without the sourceSets definitions before, but suddenly needed them after the upgrade. Never mind. All was OK for a while … but I’ve just upgraded to IDEA 2019.3, and now it tells me the sourceSets is an unresolved reference! To remove this error, I unaccountably had to insert the<JavaPluginConvention>. as a prefix to sourceSets - not sure why that wasn’t needed before. Also, I had to change main -> "main" and test -> "test" inside the sourceSets definition. With those changes in place, the project appears to build, but the tests aren’t found, again!
Link to working build.gradle.kts before the IDEA upgrade
Is there something basically wrong with my build.gradle.kts which causes this constant breakage, or is yak-shaving in this area common? Any help gratefully received.
Regards,
Vinay Sajip
请先登录再写评论。
There are similar bugs, for example that one:
https://youtrack.jetbrains.com/issue/IDEA-227502
However, every specific case should be examined separately as there are a lot of different reasons for such behavior.
Please report a bug at https://youtrack.jetbrains.com/issues/IDEA and attach sample project as well as idea.log/build.log files, see https://intellij-support.jetbrains.com/hc/articles/207241085. Enable debug logging for build.log.
Nearly two (!) years later, still the same problems. Bug reports all over the place, but no fix. For one of the most basic files in each project. I can't believe it. Why did I ever use Kotlin script...
I am really sorry about the problem. Could you please add more details and screenshot showing the problem you see? For which IDE versions did you do an upgrade? having to look into the IDE logs would be also helpful for identifying a possible issues. You can use Help | Collect Logs and Diagnostic Data action to collect the logs and upload them at https://uploads.jetbrains.com and indicate the upload id. Thank you.
In my case, it was 2019.1 -> 2019.2 -> 2019.3 as mentioned in my original post. I can't give you screen shots now, two years later - nor can I give you any logs :-(
You should be able to reproduce the problem with the information I gave in the original post, but I don't know if it's worth following up two years on. Better to look at the existing open bugs related to build.gradle.kts.
Note that in this particular case, these problems might stem not from IDEA, but from Gradle - it's an amazing tool, but what's amazing about it is its widespread adoption ;-)
>I am really sorry about the problem
Could you please add more details and screenshot showing the problem you see?
@Andrey Dernov With all due respect, are you really serious? Again?
Here, it was reported multiple times already:
Jung Rupert Thank you! The problem with highlighting can happen due to a lot of different reasons. To help you we need some additional information. Please, file an issue here - https://kotl.in/issue.