lime icon indicating copy to clipboard operation
lime copied to clipboard

Allow specifying Gradle plugins from project.xml.

Open player-03 opened this issue 1 month ago • 3 comments

This allows including published plugins or custom user-created ones. Since plugins can make arbitrary changes to the build script, this allows multiple extensions to add to app/build.gradle without overwriting each other's changes.

https://docs.gradle.org/current/userguide/plugins.html https://docs.gradle.org/current/userguide/sharing_build_logic_between_subprojects.html

Sample usage: <config:android gradle-apply-plugin="com.google.gms.google-services" />

From a quick search, there seem to be two ways to include a plugin. apply plugin is the more backwards-compatible option, so I went with that. However, plugin { } could be more future-proof. Maybe at some point we'll switch.

My main concern for now is, is "gradle-apply-plugin" distinctive enough from "gradle-plugin"? Or would another name be clearer?

player-03 avatar Nov 14 '25 01:11 player-03

This allows including published plugins or custom user-created ones. Since plugins can make arbitrary changes to the build script, this allows multiple extensions to add to app/build.gradle without overwriting each other's changes.

https://docs.gradle.org/current/userguide/plugins.html https://docs.gradle.org/current/userguide/sharing_build_logic_between_subprojects.html

Sample usage: <config:android gradle-apply-plugin="com.google.gms.google-services" />

There should be a classpath dependency added in the build.gradle too, otherwise Gradle won't be able to apply the plugin with "Plugin with id 'com.google.gms.google-services' not found." exception. That in turn requires adding the repositories paths to the app-level build.gradle (these are currently not present there). Something like this:

import groovy.swing.SwingBuilder
import java.awt.GridBagLayout
import java.awt.GridBagConstraints
import javax.swing.border.EmptyBorder

buildscript {
  repositories {
    google()
    mavenCentral()
  }

  dependencies {
    classpath 'com.google.gms:google-services:4.4.4'
  }
}

apply plugin: 'com.android.application'

. . .

IriySoft avatar Nov 17 '25 14:11 IriySoft

That's a lot of changes, and I'd rather keep the config options simple. Can't you create your own plugin to do all that?

https://docs.gradle.org/current/userguide/sharing_build_logic_between_subprojects.html

player-03 avatar Nov 17 '25 21:11 player-03

That's a lot of changes, and I'd rather keep the config options simple. Can't you create your own plugin to do all that?

https://docs.gradle.org/current/userguide/sharing_build_logic_between_subprojects.html

I can try this indeed, thanks!

IriySoft avatar Nov 18 '25 07:11 IriySoft