{"id":3727,"url":"https://github.com/groovy/groovy-android-gradle-plugin","last_synced_at":"2025-12-17T09:05:42.909Z","repository":{"id":17727931,"uuid":"20559390","full_name":"groovy/groovy-android-gradle-plugin","owner":"groovy","description":"A Gradle plugin to support the Groovy language for building Android apps","archived":false,"fork":false,"pushed_at":"2020-03-23T17:05:12.000Z","size":590,"stargazers_count":848,"open_issues_count":5,"forks_count":116,"subscribers_count":57,"default_branch":"master","last_synced_at":"2025-03-21T16:05:53.610Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Groovy","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/groovy.png","metadata":{"files":{"readme":"README.adoc","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-06T10:09:09.000Z","updated_at":"2025-01-29T09:09:13.000Z","dependencies_parsed_at":"2022-09-09T04:50:37.604Z","dependency_job_id":null,"html_url":"https://github.com/groovy/groovy-android-gradle-plugin","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/groovy%2Fgroovy-android-gradle-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/groovy%2Fgroovy-android-gradle-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/groovy%2Fgroovy-android-gradle-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/groovy%2Fgroovy-android-gradle-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/groovy","download_url":"https://codeload.github.com/groovy/groovy-android-gradle-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246068282,"owners_count":20718503,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:16:49.711Z","updated_at":"2025-12-17T09:05:42.840Z","avatar_url":"https://github.com/groovy.png","language":"Groovy","funding_links":[],"categories":["Plugins","Development Alternatives","[](https://github.com/JStumpp/awesome-android/blob/master/readme.md#development-alternatives)非Java开发安卓应用"],"sub_categories":["Android application development","Groovy","[](https://github.com/JStumpp/awesome-android/blob/master/readme.md#groovy)Groovy"],"readme":":groovyVersion: 2.4.12\n:pluginVersion: 2.0.1\n:pluginSnapshotVersion: 2.0.2\n:androidPluginVersion: 3.0.0\n\n= Groovy language support for Android\n\n*Deprecated:* This plugin has been deprecated in favor of Kotlin which has the full support of JetBrains \nand Google. The changes that go into each Android Plugin Version make it really hard for this plugin \nto keep up. As of Gradle 6.0 this plugin does not work.\n\nThis plugin adds http://groovy-lang.org[Groovy Language] support for Android applications and libraries.\n\n== Updates\nAs of 2.0.0 of this plugin only will work with the Android Gradle Plugin 3.0.0 and above. For support of lower\nversion use 1.2.0.\n\nThere is an issues when using build tool 26+ and the Groovy jar. The current work around is to use proguard or\nto use JarJar to create a jar file that does not have invoke dynamic classes.\nSee https://gist.github.com/AndrewReitz/3e1145d66a8ef3f7b578d8604ecd671c[ZarZaring the Groovy Jar for Android 26+]\nto create your own jar and avoid having to run proguard.\nSee https://github.com/groovy/groovy-android-gradle-plugin/issues/145[Github Issue] for more details.\n\n== Quick Start\nUse a https://github.com/pledbrook/lazybones[lazybones] template from\nhttps://github.com/rvanderwerf/grooid-templates[grooid-template]\n\n== Usage\n\nEdit your `build.gradle` file to contain the following:\n\n[source, groovy, subs='attributes']\n----\nbuildscript {\n  repositories {\n    jcenter()\n  }\n\n  dependencies {\n    classpath 'com.android.tools.build:gradle:{androidPluginVersion}'\n    classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:{pluginVersion}'\n  }\n}\n\napply plugin: 'com.android.application'\napply plugin: 'groovyx.android'\n----\n\nThe latest version of the Groovy Android Plugin can be found https://github.com/groovy/groovy-android-gradle-plugin/releases[here]\n\nYou must choose which version of Groovy you use. Android support is available in\nstarting at the 2.4.x releases. You will need to add the following repository to your `build.gradle` file:\n\n[source, groovy]\n----\nrepositories {\n  jcenter()\n}\n----\n\nThen you can start using Groovy by adding the groovy dependency with the `grooid` classifier:\n\n[source, groovy, subs='attributes']\n----\ndependencies {\n  compile 'org.codehaus.groovy:groovy:{groovyVersion}:grooid'\n}\n----\n\nFull list of releases can be found here https://bintray.com/groovy/maven/groovy[here].\nThen use the `assembleDebug` gradle task to test out your build and make sure everything compiles.\n\nShould you want to test development versions of the plugin, you can add the snapshot repository and\ndepend on a SNAPSHOT:\n\n[source, groovy, subs='attributes']\n----\nbuildscript {\n  repositories {\n    jcenter()\n    maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' }\n  }\n}\n  dependencies {\n    classpath 'com.android.tools.build:gradle:3.0.0'\n    classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:{pluginSnapshotVersion}-SNAPSHOT'\n  }\n}\n----\n\nGo http://oss.jfrog.org/oss-snapshot-local/org/codehaus/groovy/groovy-android-gradle-plugin/[here]\nto see what the latest SNAPSHOT version is.\n\n== Where to put sources?\n\nGroovy sources may be placed in `src/main/groovy`, `src/test/groovy`, `src/androidTest/groovy` and any `src/${buildVariant}/groovy`\nconfigured by default. A default project will have the `release` and `debug` variants but these can be configured with build\ntypes and flavors. See the https://sites.google.com/a/android.com/tools/tech-docs/new-build-system/user-guide#TOC-Build-Types[android plugin docs]\nfor more about configuring different build variants.\n\nExtra groovy sources may be added in a similar fashion as the https://sites.google.com/a/android.com/tools/tech-docs/new-build-system/user-guide#TOC-Sourcesets-and-Dependencies[android plugin]\nusing the `androidGroovy.sourceSets` block. This is especially useful for sharing code between the different test types, and also\nallows you to add Groovy to an existing project. For example\n\n[source, groovy]\n----\nandroidGroovy {\n  sourceSets {\n    main {\n      groovy {\n        srcDirs += 'src/main/java'\n      }\n    }\n  }\n}\n----\n\nwould add all of the Java files in `src/main/java` directory to the Groovy\ncompile task. These files will be removed from the Java compile task,\ninstead being compiled by GroovyC, and will allow for the Java sources\nto be referenced in the Groovy sources (joint compilation).\nPlease note, that you may need to also add these extra directories to the Java\nsource sets in the android plugin for Android Studio to recognize the Groovy\nfiles as source.\n\n== Writing Groovy Code\n\nThis plugin has been successfully tested with Android Studio and will make no attempts to add support for other IDEs.\nThis plugin will let you write an application in Groovy but it is recommended, for performance, memory and battery life,\nthat you use `@CompileStatic` wherever possible.\n\nDetails can be found on Melix's http://melix.github.io/blog/2014/06/grooid.html[blog]\nand http://melix.github.io/blog/2014/06/grooid2.html[here for more technical details]\n\n== Including Groovy Libraries\n\nIn order to include libraries written in groovy that include the groovy or\ngroovy-all jars, you will need to exclude the groovy dependency allowing the\ngrooid jar to be the one to be compiled against.\n\nFor example to use the groovy-xml library you would simply need to do exclude\nthe group `org.codehaus.groovy`.\n\n[source, groovy]\n----\ncompile ('org.codehaus.groovy:groovy-xml:2.4.3') {\n    exclude group: 'org.codehaus.groovy'\n}\n----\n\n== Skipping Groovy Compile\n\nAs of version 1.2.0 only build types/build flavors with groovy sources included in them will have\nthe groovy compile task added. If you would like to skip the groovy compilation tasks on older\nversions or on newer version wish to skip them in build types that have groovy sources you can use\nthe following to disable the groovy compiler task.\n\n[source, groovy]\n```\ntasks.whenTaskAdded { task -\u003e\n  if (task.name == 'compileDebugGroovyWithGroovyc') { # \u003c1\u003e\n    task.enabled = false\n  }\n}\n```\n\n\u003c1\u003e Disables groovy compilation only for the debug build type, simply replace\n`compileDebugGroovyWithGroovyc` with whichever compilation task you would like skip to disable it.\n\n== Configuring the Groovy compilation options\n\nThe Groovy compilation tasks can be configured in the `androidGroovy` block using the `options` block:\n\n[source, groovy]\n----\nandroidGroovy {\n  options {\n    configure(groovyOptions) {\n      encoding = 'UTF-8'\n      forkOptions.jvmArgs = ['-noverify'] // maybe necessary if you use Google Play Services\n    }\n  }\n}\n----\n\nSee https://docs.gradle.org/current/dsl/org.gradle.api.tasks.compile.GroovyCompile.html[GroovyCompile]\nfor more options.\nSee https://github.com/pieces029/is-taylor-swift-single-groovy-android/blob/master/build.gradle[Example Application]\nfor an example of using these settings to enable custom compilation options.\n\n== Only Use GroovyC\n\nFor integration with plain java projects or for working with generated files\n(such as BuildConfig) it may be desirable to only have GroovyC run in order to\nhave Java files reference Groovy files. This is roughly the equivalent of placing\nall java source files into the groovy source directory (including auto\ngenerated files like BuildConfig). In order to only have GroovyC run simply set\nthe flag `skipJavaC` in the `androidGroovy` block to true.\n\n[source, groovy]\n----\nandroidGroovy {\n  skipJavaC = true\n}\n----\n\n== Annotation Processing\n\nAs of 1.2.0 Release annotation processing is configured by default.\n\nPrevious versions would require `javaAnnotationProcessing` to be set to true.\n\n[source, groovy]\n----\nandroidGroovy {\n  options {\n    configure(groovyOptions) {\n      javaAnnotationProcessing = true\n    }\n  }\n}\n----\n\n== Android `packagingOptions`\n\nGroovy Extension Modules and Global transformations both need a file\ndescriptor in order to work. Android packaging has a restriction\nrelated to files having the same name located in the same path.\n\nIf you are using several Groovy libraries containing extension modules\nand/or global transformations, Android may complain about those files.\n\nYou can simply add the following rule:\n\n[source, groovy]\n----\nandroid {\n  packagingOptions {\n      exclude 'META-INF/services/org.codehaus.groovy.transform.ASTTransformation'\n      exclude 'META-INF/services/org.codehaus.groovy.runtime.ExtensionModule'\n      // you may need to exclude other files if you get \"duplicate files during packaging of APK\"\n      exclude 'META-INF/groovy-release-info.properties'\n      exclude 'META-INF/LICENSE'      \n  }\n}\n----\n\nThere are no problems excluding global transformation descriptors because\nthose are only used at compile time, never at runtime.\n\nThe problem comes with module extensions. Unless you statically\ncompile classes using extension modules with `@CompileStatic` they won't\nbe available at runtime and you'll get a runtime exception.\n\nThere is an alternative. The https://github.com/kaleidos/emerger[emerger]\ngradle plugin will add excludes for you and merges all extension module\ndescriptors into a single file which will be available at runtime.\n\n== Groovy Community\n\nHave questions, want to learn more!?\nCome ask questions or help others in #android in the Groovy Community Slack\ngroovycommunity.com[Sign-Up Here]\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgroovy%2Fgroovy-android-gradle-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgroovy%2Fgroovy-android-gradle-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgroovy%2Fgroovy-android-gradle-plugin/lists"}