https://kotlinlang.org logo
#android
Title
# android
a

Allan Wang

06/04/2019, 12:37 AM
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

gildor

06/04/2019, 1:14 AM
Do you need just a plugin in buildSrc?
a

Allan Wang

06/04/2019, 1:15 AM
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

gildor

06/04/2019, 1:16 AM
See official samples, they have examples. You have to apply Kotlin plugin of course, or, even better, use kotlin-dsl plugin
a

Allan Wang

06/04/2019, 1:17 AM
g

gildor

06/04/2019, 1:17 AM
Yes, this sample
Also, you can use precompiled script plugins, requires even less boilerplate
a

Allan Wang

06/04/2019, 1:19 AM
Just by copying the sample, it isn’t registering the dsl
g

gildor

06/04/2019, 1:20 AM
This is just tooling problem
a

Allan Wang

06/04/2019, 1:20 AM
and from the samples it doesn’t look like my root gradle file should matter since theirs is empty
g

gildor

06/04/2019, 1:20 AM
Build from command line
It definitely works
Root Gradle? Not really, only one from buildSrc
a

Allan Wang

06/04/2019, 1:28 AM
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

gildor

06/04/2019, 1:42 AM
why it’s different?
a

Allan Wang

06/04/2019, 1:43 AM
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

gildor

06/04/2019, 1:44 AM
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

Allan Wang

06/04/2019, 1:44 AM
copied example, which shows that kotlin isn’t configured, even after adding the kotlin plugins
g

gildor

06/04/2019, 1:45 AM
Did you also copied buildSrc/build.gradle?
a

Allan Wang

06/04/2019, 1:45 AM
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

gildor

06/04/2019, 2:04 AM
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

Allan Wang

06/04/2019, 2:20 AM
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

gildor

06/04/2019, 2:34 AM
Invalidate caches
¯\_(ツ)_/¯
a

Allan Wang

06/04/2019, 5:33 AM
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

gildor

06/04/2019, 5:34 AM
No way, just ignore
a

Allan Wang

06/04/2019, 5:30 PM
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

gildor

06/05/2019, 8:31 AM
How this related to jitpack?
No need to specify Kotlin version, as I said above, you don't need Kotlin plugin or stdlib
a

Allan Wang

06/06/2019, 2:40 AM
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

gildor

06/06/2019, 2:40 AM
the warning stops the jar file from being generated
It is not, it’s just a warning
a

Allan Wang

06/06/2019, 2:41 AM
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

gildor

06/06/2019, 2:44 AM
hmm, how does it even work? You don’t have settings.gradle file in buildSrc
so buildSrc shouldn’t work
a

Allan Wang

06/06/2019, 2:45 AM
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

gildor

06/06/2019, 2:45 AM
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

Allan Wang

06/06/2019, 2:47 AM
Oh I see. I’ll try that
g

gildor

06/06/2019, 2:47 AM
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

Allan Wang

06/06/2019, 2:49 AM
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

gildor

06/06/2019, 2:50 AM
But how do you apply your plugin? Do you have an example?
a

Allan Wang

06/06/2019, 2:50 AM
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

gildor

06/06/2019, 2:54 AM
sooo, this plugin is published?
because this is another project
a

Allan Wang

06/06/2019, 2:56 AM
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

gildor

06/06/2019, 3:05 AM
yes, your exsitng config in buildSrc doesn’t have publishing, so this was a problem
4 Views