Does anyone have a multi module project with a kot...
# android
a
Does anyone have a multi module project with a kotlin gradle plugin? I have an existing plugin (https://github.com/AllanWang/KAU/tree/dev/buildSrc) and I’d like to convert it to use kotlin, but I seem to be missing some dependencies. Looking at other examples online (https://www.klg71.de/post/kotlin_gradle_plugin/), it seems like adding the kotlin plugin should fix it, but I’m getting more errors which makes me believe my root build gradle is wrong
g
Do you need just a plugin in buildSrc?
a
I have a relatively simple one above, but I’d like to convert it to kotlin from groovy. I’ve come across some issues on getting the build gradle kts set up, and also in using the project in other modules (names from
extensions.create
aren’t registered)
g
See official samples, they have examples. You have to apply Kotlin plugin of course, or, even better, use kotlin-dsl plugin
a
g
Yes, this sample
Also, you can use precompiled script plugins, requires even less boilerplate
a
Just by copying the sample, it isn’t registering the dsl
g
This is just tooling problem
a
and from the samples it doesn’t look like my root gradle file should matter since theirs is empty
g
Build from command line
It definitely works
Root Gradle? Not really, only one from buildSrc
a
Thanks. Running
tasks
seems to fix the tooling issue. The samples are a bit different from what I’m used to but I’ll figure it out as I go
g
why it’s different?
a
For one, meta inf seems generated from
gradlePlugin
. id looks like the package name, yet in the example it isn’t. I checked the generated jar, and while
build
resolves errors in the
gradle.build
, I’m still getting errors in my classes. None of them are even in the resulting jar, and the command succeeds, so it’s just skipping everything
g
I see that you actually use your plugin just to provide versions and some helper class If you do not plan to publish it, you can avoid creating plugin, just declare this code and it will be available in our modules of this project, no need to apply them
a
copied example, which shows that kotlin isn’t configured, even after adding the kotlin plugins
g
Did you also copied buildSrc/build.gradle?
a
The
kotlin("jvm") version "1.3.31"
stuff was added per Android Studio. It doesn’t work without it either
Oh it might be because things aren’t in the kotlin folder, though from the tooling it isn’t marked as a resource folder. I’ll try that too
g
you don’t need kotlin plugin, kotlin-dsl plugin is enough
Kotlin will not work in
groovy
dir, move to
kotlin
or
java
also you don’t need
stdlib
in dependeicnes, kotlin-dsl will apply it
a
It appears to be another tooling issue since creating the jar works and it looks fine, but all the kotlin functions aren’t recognized
g
Invalidate caches
¯\_(ツ)_/¯
a
Do you know the proper way to deal with
WARNING: Unsupported Kotlin plugin version.
? All the examples supply their own kotlin versions, yet the embedded
kotlin-dsl
version is constant. Specifying it myself doesn’t resolve the issue. I’m currently using kotlin
1.3.31
, whereas Gradle
v5.1.1
uses kotlin-dsl
1.1.1
with kotlin
1.3.11
g
No way, just ignore
a
Unfortunately it doesn’t work with jitpack anymore. Guess I have to revert. Another reason why I’d be interested to see a production project. Why would we have to specify kotlin versions if the dsl is embedded and doesn’t always work with new versions?
g
How this related to jitpack?
No need to specify Kotlin version, as I said above, you don't need Kotlin plugin or stdlib
a
https://jitpack.io/ca/allanwang/kau/8052a9a/build.log If you look for
WARNING: Unsupported Kotlin plugin version.
, it appears as though the warning stops the jar file from being generated. Do I not need kotlin gradle plugin? This is my main build gradle: https://github.com/AllanWang/KAU/blob/kotlin-plugin/build.gradle.kts And all the subproject configs are skipped for the kotlin-dsl project. The only addition is the kotlin gradle dependency, but isn’t that required? And what about any other dependencies with different kotlin versions?
To clarify, my current project gradle is clean: https://github.com/AllanWang/KAU/blob/kotlin-plugin/buildSrc/build.gradle.kts No other dependencies
g
the warning stops the jar file from being generated
It is not, it’s just a warning
a
But if you compare the output with another one the log is different afterwards too
It appears that jitpack never compiles it. Do you know of a project using kotlin dsl with jitpack?
g
hmm, how does it even work? You don’t have settings.gradle file in buildSrc
so buildSrc shouldn’t work
a
I have one in the parent project. It shouldn’t be necessary for sub modules right? It was never that way for non kts builds
g
maybe it was changed in later versions of Gradle
no, buildSrc is completely separate project
and in recent versions of Gradle is now required to hav settings.gradle for buildSrc
a
Oh I see. I’ll try that
g
but again, it’s just what I noticed
I’m not sure about your problem, about which problem are you talking? I mean what kind jar is not generated?
also, as I mentioned above, I don’t understand why you need plugin at all, your Versions and ChangelogGenerator already available in classpath, no need to expose them again using extensions
a
When I use the new version, my plugin is not found. When I look at old builds, there is no configuration for that module, but instead there is:
Copy code
> Task :gradle-plugin:compileJava NO-SOURCE
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2

> Task :gradle-plugin:compileGroovy

> Task :gradle-plugin:processResources
> Task :gradle-plugin:classes
> Task :gradle-plugin:jar
> Task :gradle-plugin:install
in the new one, there is just:
Copy code
> Configure project :gradle-plugin
WARNING: Unsupported Kotlin plugin version.
The `embedded-kotlin` and `kotlin-dsl` plugins rely on features of Kotlin `1.3.11` that might work differently than in the requested version `1.3.31`.

> Configure project :kpref-activity
Generating public XML

> Configure project :mediapicker
Generating public XML

> Configure project :searchview
Generating public XML

> Task :clean UP-TO-DATE
> Task :about:clean
> Task :adapter:clean
> Task :colorpicker:clean
> Task :core:clean
> Task :core-ui:clean
> Task :gradle-plugin:clean
> Task :kpref-activity:clean
And nothing after clean, whereas all the other submodules are build. They haven’t been converted to kts though. I have other issues with the conversion for now
g
But how do you apply your plugin? Do you have an example?
a
Yeah once kts works, I can probably remove extensions. Back with groovy I accessed the values with extensions; I might have been able to just use the classes then too
I use extensions to call it, but again I think with kts
configure<>{ }
might work
The other example is in the project itself, which is unrelated to jitpack and works: https://github.com/AllanWang/KAU/blob/dev/build.gradle#L29
g
sooo, this plugin is published?
because this is another project
a
The plugin is in KAU. I use it both within that project for versioning and in other projects through jitpack
https://jitpack.io/ca/allanwang/kau/02f97ad/build.log I added the maven plugin and settings.gradle and it does compile now so it seems fixed. thanks!
g
yes, your exsitng config in buildSrc doesn’t have publishing, so this was a problem