This message was deleted.
# community-support
s
This message was deleted.
v
No, and you shouldn't need to. You define the version when you depend on the plugin in the build script of the build that is building the PSP and apply it in the PSP without version.
l
True story but then I have to track the version of Kotlin and Android Gradle Plugin in both builds. I have 2 version catalogs, one for the build that provides the precompiled script plugins and the other for that build that applies the KGP and AGP. Maybe this is not optimal?
j
you can use only one catalog
v
You can have any amount of version catalogs you want
True story but then I have to track the version of Kotlin and Android Gradle Plugin in both builds.
Why? If you depend on those plugins in your PSP plugin build and then apply your PSP plugin that applies those plugins, why do you then need to track the versions again in the consumer build?
l
@Vampire Usually thats the approach I would go with, but I couldn't get it to work to apply the AGP via a PSP. I have a
project-gradle.kts
which is applied in the project-level build.gradle.kts of the main project. project-gradle.kts:
Copy code
plugins {
    /*
     * It is not possible to add android.application and android.library at the same time.
     * The same applies for kotlin.android and kotlin.jvm.
     */
    // Provides version updater
    id("com.github.ben-manes.versions")
    // Provides code analyzing
    id("de.acme.configuration.code-analyzing")
    // Provides suggestions for build optimizations
    id("com.osacky.doctor")
}
project-level build.gradle.kts:
Copy code
plugins {
    // Provides code analyzing and a gradle versions updater
    alias(libs.plugins.dc.project)
    // Provides android support
    alias(libs.plugins.android.application).apply(false)
    alias(libs.plugins.android.library).apply(false)
    // Provides kotlin support
    alias(libs.plugins.kotlin.android).apply(false)
    alias(libs.plugins.kotlin.jvm).apply(false)
}
In the latter snippet, the first plugin is my PSP followed by the AGP plugins for android.application and android.library. I know android is not your sphere but do you think it is possible to apply android and kotlin plugins via the PSP?
When I add android.application and android.library to
plugins
block of project-gradle.kts I get following error:
Copy code
FAILURE: Build failed with an exception.

* Where:
Precompiled script plugin 'D:\dev\android\workspace\dcapps\configuration-plugin\src\main\kotlin\de\acme\configuration\project.gradle.kts' line: 1

* What went wrong:
An exception occurred applying plugin request [id: 'com.android.library']
> Failed to apply plugin 'com.android.internal.library'.
   > Cannot add a configuration with name 'androidJdkImage' as a configuration with that name already exists.
Exception is
org.gradle.api.plugins.InvalidPluginException: An exception occurred applying plugin request [id: 'com.android.library']
v
I don't fully get the question. You say you cannot apply
com.android.application
and
com.android.library
together. In the upper version you also don't do that, you just add them to the classpath (
apply(false)
). But if you add them to the plugins block of your psp, you are trying to apply them both, that's something different. If you just want them on the classpath when your psp is applied, just depend on them in your psp-building project. If you want to apply those plugins via psp, you should probably have to different psp, one for either and both could apply another psp that does common things.
l
Damn I have problems with the correct wording. I don't want to apply them via the PSP I want to have them in the classpath in the main project via PSP. So what I'm looking for is this:
If you just want them on the classpath when your psp is applied, just depend on them in your psp-building project.
Can you help me with that? What exactly do I have to do?
v
Ah, now I understand your confusion. You add them with
apply(false)
to your psp, right?
That is a no-op and actually is ignored. The plugin is applied instead instead of throwing an error due to invalid usage (I have an open bug report for that)
Also it does not make any sense to have
apply(false)
in a psp, as the only sense for
apply(false)
is to bring a plugin to the classpath. But with a psp, the plugin already is on the classpath purely by having the
implements
or
runtimeOnly
dependency on it. That's also why you can apply it without verison, because it is already on the classpath.
So inside the actual psp you do not have to do anything
l
If I get u right I can omit adding android and kotlin plugins to the classpath in project-level build.gradle.kts because they are already added to the classpath since they have
implementation
dependency on it in PSP build
Now my project-level build.gradle.kts plugins block looks like:
Copy code
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
    // Provides code analyzing and a gradle versions updater
    alias(libs.plugins.dc.project)
}
More slimmer and it also works like a charm ❤️
👌 1