could it be that the runtimeOnly() helped?
No.
it won’t exclude transitive deps which are simply too many to exclude manually, and that would be a fragile solution in this case.
I’s not only tedious, the fragility is also that some other library might need the same library and thus excluding it would break it.
I learned that IDEA creates a temporary task of type JavaExec when running Java apps;
There are again two things to consider.
- You can just run
gradle run from IntelliJ and it will behave the same as from CLI, just do not go to the class and use the Gutter icon to run.
- If for some reason you have to use that Gutter icon to run the class directly, then whether IntelliJ creates a temporary Gradle task or not depends on your IDE settings. If you have Gradle delegation enabled, then yes. If you have Gradle delegation disabled, then it does not use Gradle at all to run the class.
For this case, using the class-run and Gradle delegation enabled, you can indeed just enrich the task in your build script if you don’t mind having IDE-specifics in the build script.
unfortunately placing the following into build.gradle.kts doesn’t seem to help, probably because it’s only being used for existing tasks only):
No, that’s wrong.
It is executed also for that task, but it is overwritten again by IntelliJ, as its integration uses the bad-practice afterEvaluate to do its configuration. Due to that, you also have to use afterEvaluate to do your customization after IntelliJ did theirs.
The usual shenenigans when using that aweful construct.
Besides that, never use ´tasks.withType<…> { … }, or you break task-configuration avoidance for all those tasks and thus always configure all tasks of that type for each and every build, even if you are not going to run any of it. Always use tasks.withType<…>.configureEach { … }instead which will preserve task-configuration avoidance. So add theconfigureEach, and wrap it in a bad-practice afterEvaluate { … }` and it will work.
But maybe you should not enrich all tasks of type JavaExec or you also add these dependencies to a lot more tasks where it just pollutes classpaths or potentially breaks tasks. So what you most probably want is afterEvaluate { tasks.withType<JavaExec>().matching { it.name.endsWith(".main()") }.configureEach { ... } }.
So far the cleanest solution I was able to come up with my limited Gradle understanding, is to use properties: -Pproduction combined with dependencies { if (!production) { implementation(libs.vaadin.dev) } }
That’s of course also an option, yes.