gradle , methodMissing no longer being called on extension after upgrading to Gradle 2.2

methodMissing no longer being called on extension after upgrading to Gradle 2.2


Tag: gradle

Our build uses a custom plugin extension in gradle that has dynamic methods. This worked fine in gradle 2.1, but methodMissing is no longer called in 2.2 and I get the following exception (here's the caused by part):

Caused by: org.gradle.api.internal.MissingMethodException: Could not find method common() for arguments [api] on org.gradle.api.interna[email protected]1bef1304.
at org.gradle.api.internal.AbstractDynamicObject.methodMissingException(
at org.gradle.api.internal.AbstractDynamicObject.invokeMethod(
at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(
at org.gradle.api.internal.artifacts.dsl.DefaultComponentModuleMetadataHandler_Decorated.invokeMethod(Unknown Source)

How do I get dynamic functions working in our build system with gradle 2.2?

The Background:

These dynamic methods are used for several things, but one is to simplify how projects depend on other projects (it is a very large system with over 80 subprojects that each may have multiple named APIs (public, internal, add-on, etc)).

This is my Plugin's apply:

void apply(Project project) {
   project.subprojects.each { subproject ->
      subproject.extensions.create("modules", ModuleExtension.class ) }

ModuleExtension has no variables or functions other than methodMissing:

def methodMissing(String name, args)
    //return project dependency based on name/args. This no longer gets called in 2.2!

Sample usage in a gradle file:

dependencies {
   compile module.nameOfModule( "name of api" )

I've also overrode the following in ModuleExtension just to see if they are getting called, but they are not:

def invokeMethod(String name, args)
def propertyMissing(String name)
def propertyMissing(String name, value)


I'm actually unable to reproduce this issue in Gradle 2.2. However, this is a somewhat misuse of Gradle extensions. If you simply want a globally available object I would simply add it as a project extra property. This has the added benefit of not having to be created for every subproject, since projects inherit properties from their parent.

ext {
    modules = new ModuleExtension()

Edit: This is due to the new support for module replacements introduced in Gradle 2.2. The symbol modules within a dependencies block now delegates to a ComponentModuleMetadataHandler rather than your extension. You'll either have to rename your extension something other than modules or qualify the call by using project.modules.nameOfModule.


How to elegantly build selected parts of a project

I have a project where I ideally wanted to be able to write something like this: gradle build or gradle build -Pparts=part1,part5 Where the first command builds the whole project with a core part and all other parts. The second command builds the core part and selectively part1 and part5....

How to declare a constant that is visible to all modules' build.gradle file?

I have a project that has multiple Modules - libraries and applications. Everytime a new version of Android comes out, I need to upgrade the targetSdk, compileSdk, buildToolsVersion, etc. for all the modules. A constant could help with this tedious work! How could I define project-level constant that is visible...

what is gradle missing to map hibernate?

I have unittest to my java project. My code uses hibernate. When i run the test using junit - everything passes. When I run the test using gradle - I get a mapping error: Caused by: org.hibernate.MappingException: Unknown entity: linqmap.users.interfaces.model.UserRecord and the class: @Entity @Table(name = "users") public class UserRecord...

Automatically copy .so files from NDK library project?

Using Android Studio with Gradle 1.2.3. I have an NDK library project A that produces a number of .so files in its own libs folder. Though, I cannot see the reference to this folder anywhere in the build.gradle file. When I reference library A from my app MyApp I...

Phonegap: Command failed with exit code 8

I'm setting up an environment for Phonegap developing, and I'm getting some trouble to finally build and run an app for Android. When I try to execute build for Android, I got the following error: Running: C:\Users\Renan\workspace_html5\FIAP\Phonegap\phonegap-test\test\platfor ms\android\gradlew cdvBuildDebug -b C:\Users\Renan\workspace_html5\FIAP\Phonegap \phonegap-test\test\platforms\android\build.gradle -Dorg.gradle.daemon=true Unzipping C:\Users\Renan\.gradle\wrapper\dists\gradle-2.2.1-all\2m8005s69iu8v0oi...

Proguard - also use proguard files from modules

My projects build.gradle looks like following: android { compileSdkVersion 22 buildToolsVersion "22.0.1" defaultConfig { applicationId "..." minSdkVersion 15 targetSdkVersion 22 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), '' } } } dependencies { compile project(':androKnife') } And my androKnife module does have it's own...

Gradle Exec : Why it is not running in configuration phase?

Here is my: build.gradle task makeDirectoryStructure(type:Exec){ description 'Creates directory structure .' commandLine 'mkdir' args '-p' ,'top_dir/sub_dir_1/sub_dir_2' println "This line is printed in configuration phase." } Now, since I haven't used '<<' or< 'doFirst/doLast', I expect mkdir to be executed in configuration phase i.e. whenever the build script is compiled. For...

Gradle & Jacoco: Get jacoco reports for Test-type task other than “test”

When I run gradlew test jacocoTestReport the task jacocoTestReport runs and I get a a test report. When I run gradlew integTest jacocoTestReport the task jacocoTestReport is skipped. Here's the relevant excerpts from my build.gradle: apply plugin: 'jacoco' jacocoTestReport { group = "Reporting" description = "Generate Jacoco coverage reports after...

Android Studio and gradle

I tried importing Xabber ( GitHub ) within Android Studio , I did the git init etc . Now I find that I can start the app for that problem Gradle , I've looked everywhere , but could not find anything that would work .. The problem is: Error:Execution failed...

Spring Boot Actuator Info Endpoint Version from Gradle File

I'd like the /info actuator endpoint from my Spring Boot (1.2.4.RELEASE) application to return the version as specified in the build.gradle file. In my build.gradle file I have a line as so: version = '0.0.1-SNAPSHOT' I am using yaml configuration file. Right now I have the version duplicated as so...

How to use Library from GitHub in android App

I downloaded this library to use in my app, however, I can't get Android Studio to do the gradle build now. Anytime I try, I get "error:configuration with name 'default' not found". I've tried several other StackOverflow answers, but I still can't compile. My dependencies (from build.gradle Module: app) dependencies...

Choosing specific ports on local development server for non-default modules

In my build.gradle file, I use the following config for my non-default (module2) AppEngine gradle module: appengine { downloadSdk = true httpAddress = "" httpPort = 8081 appcfg { email = "[email protected]" oauth2 = true } } However, when I run my "Google AppEngine configuration", the module still starts on...

Adding Android AppWidget just for one Product Flavor

I have two gradle product flavors: for prod and for stage server. productFlavors { stage { // stage specific stuff } production { // production only } } Also I have an AppWidget must be able only for stage now. I think I should hide my AppWidgetProvider in manifest: <receiver...

Is it possible to exclude specific build variant when using flavor Dimensions?

When using Gradle flavorDimensions, is it possible to exclude specific variants? For example - android { ... flavorDimensions "abi", "version" productFlavors { freeapp { flavorDimension "version" ... } x86 { flavorDimension "abi" ... } } the following build variants will be created: x86-freeapp-debug x86-freeapp-release arm-freeapp-debug arm-freeapp-release mips-freeapp-debug mips-freeapp-release x86-paidapp-debug x86-paidapp-release...

android studio “Gradle project sync failed. Basic functionality (e.g. editing, debugging) will not work properly”

I don't understand the error says Error:Failed to create parent directory 'C:\Program Files\Android\Android Studio\gradle\daemon' when creating directory 'C:\Program Files\Android\Android Studio\gradle\daemon\2.2.1' ...

Add project on outer level as dependency to module

I have a project that looks something like this: mainProject/ mainModule proj1/ module1 proj2/ module2 and what I'm trying to do is add proj1 and proj2 as dependencies to mainProject. I've gotten it to the point where I can import classes from the projects and everything seems to work fine...

Exclude Package From Gradle Dependency

I'm experiencing an issue where multiple versions of the same class are showing up in my classpath. The class in question is The version I want to use is brought in by However, we also use the Jira rest client library which has a dependency on the older...

Gradle Assemble Debug is Successful But Does Not Work [duplicate]

This question already has an answer here: Why won't gradle run from within a jenkins job 2 answers After following instructions here: apparently you're supposed to chmod +x gradlew then ./gradlew assembleDebug which leads to the following output: /gradlew assembleDebug :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72200Library...

Can't use RecyclerView in my Android library project

I have an Android library project and want to include a class that extends RecyclerView.Adapter. My build.gradle file includes the following: apply plugin: '' dependencies { compile '' } Despite this, I cannot import RecyclerView in any java file; it even does not show up in the code completions popup...

How to create different build variants pointing to different Servers?

I am using for auto building my app. I want to generate three different APK's each pointing to different Service URL's. How can I make use of buildVariants (productFlavors in gradle). But I'm not able to figure out where to set the three URL's in the Gradle. How can...

Using GradleBuild , how to specify individual task to execute from tasks list

I've two gradle files : build.gradle apply from :'other.gradle' task hiHelloWrapper(type: GradleBuild) { buildFile = 'other.gradle' tasks = ['hi','hello'] } other.gradle task hello<<{ println 'hello from other' } task hi<<{ println 'hi from other' } Now, when I execute >gradle hiHelloWrapper it results in both tasks hi and hello being...

Using ant.replace in gradle

I want to use ant's replace task to replace token in one of the files like this: version.txt version.number=${versionNumber} build.gradle task writeVersion { ant.replace { file 'version.txt' token 'versionNumber' value '1.0.0' } } but it is giving me following error :- A problem occurred evaluating root project '1.01-Exercise-RunYourFirstTask'. > replace...

Gradle : Cannot add task ‘:helloFromBuild1′ as a task with that name already exists

Gradle gives the below error in terminal. * What went wrong: A problem occurred evaluating script. > Cannot add task ':helloFromBuild1' as a task with that name already exists. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log...

How to exclude dependencies of other subproject in Gradle build?

I am developing a sub-project that is a part of the huge multi-project Gradle build. I need some Java classes from these other sub-projects, but I do not need any dependencies they drag in because some libraries I use require different versions of these. I initially configured the needed subprojects...

Android Studio work with module

In my project I've got a main package and a module (app 2). For the module, I use standard application -> import to project -> change it as library and make dependencies (compile project(':app2')). Everything is ok but when I compile, it installs on my cell phone as two individual...

Android Studio Best way import module from other repository

I have to import a project from a Github repository as a module inside an Android Studio project that it committed into another repository. The project I have to import from Github will be updated constantly so it means that I'll have to refresh every now and again for having...

Gradle multi-project custom build.gradle file name

I have a multi-project Gradle build, which is currently configured through a single build.gradle file. There are over 70 modules in this project, and the single (gigantic) build.gradle file has become cumbersome to use, so I'd like to split it into small per-module buildscript files. Now, I don't want to...

Gradle Jar structure is different than the real project structure

I'm trying to build my project with gradle but for some reason the resources are put on a different level than their real level. Here's the build: apply plugin: 'java' version = '1.1' archivesBaseName = 'DesktopOmegle' repositories { //mavenCentral() maven { url '' url "" } } dependencies { compile...

Gradle - Error:Failed to find: com.squareup.okhttp:okhttp:2.4.0

I just try to use OkHttp but I have the following issue when I sync my gradle file with Android Studio : Error:Failed to find: com.squareup.okhttp:okhttp:2.4.0 Here is the dependencies part of my build.gradle file : dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile '' compile '' compile 'com.squareup.okhttp:okhttp:2.4.0' }...

Duplicate entry for class in gradle

I am trying to implement ken burns view in android studio in my app, i have importted the folder which contains its classes, but gradle gives me this error Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'. > duplicate entry: com/flaviofaria/kenburnsview/MathUtils.class Here is my build.gradle apply plugin: '' android { compileSdkVersion 21...

How to download a library dependence on gradle for external use?

I have a project on PhoneGap and I am trying to build a plugin to use a FilePicker library. So, I build one Android Studio Project and I have it working. So, right now, that I know that I know how to do it, I just need to know how...

Android build project error trying to build apps > 65K (65536) methods

I have added these two new dependencies in my build.gradle compile '' compile '' And right now, I can't build my project because I've got an error. I have found information about the error and the solution that I have found says that I have to add ... compile 'com.parse.bolts:bolts-android:1.+'...

Incorrect liferay-plugins dependency

In following dependency is defined: dependencies { classpath group: "com.liferay.portal", name: "portal-service", version: "7.0.0-SNAPSHOT" } How can a 6.2.x version have a dependency on 7.0.0 version? Is it a bug? When I peek to the history of the file, the dependency has always been there. I am not able...

Get the Git Working Branch in Gradle on Jenkins

I want to have the current Git branch in the Version name of my Android app. I built in this snippet from here into my build.gradle: def getWorkingBranch() { // Triple double-quotes for the breaklines def workingBranch = """git --git-dir=${rootDir}/git --work-tree=${rootDir}/.. rev-parse --abbrev-ref HEAD""".execute().text.trim() print "Working branch: " + workingBranch...

Gradle : Stackoverflow Error

I'm using Gradle in IDEA and got below output. * What went wrong: A problem occurred evaluating script. > java.lang.StackOverflowError (no error message) * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. ...

Gradle: Adding sources.jar file within /lib folder of published along with all my other dependencies

I have a java project that I am building using gradle. I am releasing a folder for my project and I want to add the sources.jar for my project to the /lib subfolder within I am able to create a sources.jar file along with my file but...

Creating and referencing a library for Android project (using command line and gradle)

I need to create an Android app that uses the OpenCV library, and I would like to do this using the command line (linux) only. Before I start I wanted to get a feel for creating projects that use libraries, but I am having trouble referencing a sample library I...

Set variable to Gadle build file

This is kind of a follow-up question to this one. I want to "know" from which branch may Android app was built during the execution of the Gradle build.gradle file and add the branch name to the versionName of my app. This is my naive approach: apply plugin: 'android' def...

gradle execute task after build

I am using the build in gradle. My build.gradle file like this: project('a'){ apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'application' buildDir = 'build' [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' repositories { mavenCentral() } dependencies { compile 'org.slf4j:slf4j-api:1.7.7' } } When I input the gradle build in the command, I want...

Android studio gradle flavor dimensions build varients not working correctly

I have two dimensions of an app, call then green and blue. There will only be these two dimensions but an unlimited number of product flavors. This is the way I'm setting it up in gradle flavorDimensions "green", "blue" productFlavors { one { applicationId "" versionCode 1 versionName ""; flavorDimension...

Install gradle on Centos

I'm trying to install gradle for building android app with the help of Jenkins. But I'm not able to find the link to download gradle for Centos. I tried to use binaries from, but when I unzipped I got gradle.bat file inside bin directory which tells me that this...

duplicate an android studio project

Im using Android studio and Im trying to deplicate an existing project to make another new. i search in the web and also at the forum and i found this method : - copy the folder of the old project and rename it - change the package name in the...

Deploy closed source aar maven repo to github

I am using the following guide to publish a closed source aar as maven repo on github: The github repo I am publishing to: In my file I have: repositories { maven { url "" } } dependencies { compile 'com.adscendmedia.sdk:adscendmedia:1.0.1' } However Android studio results in...

Paid and Free versions of android app

I am wondering what is the best way to have two different versions of an android app. I would like to have version of my app with ads and one without ads (the paid one). What is the easiest way to achieve this ? I have found something called version... org.gradle.process.internal.ExecException

I am using Android studio 1.2.2. I've integrated maps 4 work sdk, after this the Build is failing, We are using google play services lib in our project (using only*). Now after integrating googlemaps_sdk_m4b_lib, the build is not getting generated. before to this inte Tried looking for including only...

Visualizing gradle dependencies in Intellij

Is there a way to visualize project dependencies for a gradle project in Intellij? For a maven project, if you right click in the pom.xml you get a Show dependencies option but there I don't see such an option for a gradle project. Does this feature exist for gradle project?...

scala minecraft forgemod 'gradle runClient' gives runtime exception

I'm trying to use akka inside my scala based mod. The when testing using "gradle runClient" it gives errors, best I can tell its missing the akka library at runtime. I don't see how to add akka library though. If it helps my project is here: Any advice would...

Roboblender use annotation databases with multiple modules

I'm following the steps from the RoboBlender Wiki to use annotations database but I keep getting java.lang.IllegalStateException: Unable to use annotation database(s) because it cannot find AnnotationDatabaseImpl I am using Android Studio and Gradle. The project consists of multiple modules. app moduleA moduleB moduleC Here is what I added to...

Issue building project on Android Studio - support-v4

I'm having trouble running and building apk's on my Android studio Project, I'm searching and searching but can't find any suitable solution for my problem. Gradle console stacktrace: trouble writing output: D:\android-sdk-windows\Shairlook-Def-git\app\build\intermediates\pre-dexed\debug\internal_impl-22.0.0-f0c61aa475a654ffa9a9c544ec7d938bf31cfae2.jar (El sistema no puede encontrar la ruta especificada) FAILED FAILURE: Build failed with an exception. * What went...

Gradle not using latest version of the support library?

I've been using the package -- specifically the RecyclerView class (among others but this is where the problem is). It was working fine until earlier today it randomly seems to default to an earlier version of the package now. I say that because: When I try calling myRecyclerView.addOnScrollListener(myScrollListener), myRecyclerView.getChildAdapterPosition(myView)...