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

Question:

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(AbstractDynamicObject.java:68)
at org.gradle.api.internal.AbstractDynamicObject.invokeMethod(AbstractDynamicObject.java:56)
at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:172)
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)

Answer:

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.


Related:


Automatically copy .so files from NDK library project?


android-studio,gradle,android-ndk
Using Android Studio 1.2.1.1 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...

Android Studio Best way import module from other repository


android,git,gradle,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...

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


gradle
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...

scala minecraft forgemod 'gradle runClient' gives runtime exception


scala,gradle,akka,minecraft,minecraft-forge
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: https://github.com/tesract/NilCraft Any advice would...

Android studio gradle flavor dimensions build varients not working correctly


android-studio,gradle,android-gradle,build.gradle,android-productflavors
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 "com.app.green.one" versionCode 1 versionName "1.0.0.1"; flavorDimension...

Using ant.replace in gradle


replace,ant,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...

Duplicate entry for class in gradle


java,android,android-studio,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'. > java.util.zip.ZipException: duplicate entry: com/flaviofaria/kenburnsview/MathUtils.class Here is my build.gradle apply plugin: 'com.android.application' android { compileSdkVersion 21...

Phonegap: Command failed with exit code 8


android,cordova,gradle
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...

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


java,gradle,jacoco
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...

Roboblender use annotation databases with multiple modules


android,gradle,dependency-injection,roboguice,roboblender
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...

How to exclude dependencies of other subproject in Gradle build?


java,eclipse,gradle,dependencies,dependency-management
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...

Incorrect liferay-plugins dependency


gradle,dependencies,liferay,liferay-6.2
In https://github.com/liferay/liferay-plugins/blob/6.2.x/build-plugins.gradle#L9 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...

Gradle not using latest version of the support library?


android,android-studio,gradle,android-support-library,recyclerview
I've been using the android.support.v7.widget 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)...

Issue building project on Android Studio - support-v4


android,gradle,android-gradle,build.gradle
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: Adding sources.jar file within /lib folder of published dist.zip along with all my other dependencies


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

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


cordova,android-studio,gradle,android-gradle,cordova-plugins
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...

gradle execute task after build


gradle,build.gradle
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...

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


gradle
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...

Add project on outer level as dependency to module


android,intellij-idea,gradle
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...

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


android,android-studio,gradle,build,android-gradle
I have added these two new dependencies in my build.gradle compile 'com.android.support:appcompat-v7:22.2.0' compile 'com.android.support:design:22.2.0' 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.+'...

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


java,android,linux,opencv,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...

Spring Boot Actuator Info Endpoint Version from Gradle File


gradle,spring-boot
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...

Deploy closed source aar maven repo to github


android,git,maven,github,gradle
I am using the following guide to publish a closed source aar as maven repo on github: http://andydyer.org/blog/2014/10/05/hosting-android-dependencies-on-github/ The github repo I am publishing to: https://github.com/tabishfayyaz/test-sdk In my gradle.build file I have: repositories { maven { url "https://github.com/tabishfayyaz/test-sdk/blob/master" } } dependencies { compile 'com.adscendmedia.sdk:adscendmedia:1.0.1' } However Android studio results in...

Install gradle on Centos


jenkins,gradle
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 https://gradle.org/downloads/, but when I unzipped I got gradle.bat file inside bin directory which tells me that this...

How to use Library from GitHub in android App


android,github,gradle,libraries
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


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

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


android,gradle,android-gradle
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?


java,hibernate,gradle
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...

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


android,gradle
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...

Set variable to Gadle build file


gradle
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...

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException


android,android-studio,gradle,multidex
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 com.google.android.gms.tagmanager.*). Now after integrating googlemaps_sdk_m4b_lib, the build is not getting generated. before to this inte Tried looking for including only...

Paid and Free versions of android app


android,gradle,android-version
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...

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


android,android-studio,gradle,okhttp
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 'com.android.support:appcompat-v7:22.1.1' compile 'com.google.android.gms:play-services-maps:6.5.87' compile 'com.squareup.okhttp:okhttp:2.4.0' }...

Android Studio work with module


java,android,android-studio,gradle
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...

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


gradle,exec,mkdir
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 multi-project custom build.gradle file name


gradle,build,multi-project
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...

Visualizing gradle dependencies in Intellij


intellij-idea,gradle,intellij-14
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?...

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


android-studio,gradle,android-gradle
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' ...

Gradle Jar structure is different than the real project structure


java,jar,gradle,build
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 'http://oss.sonatype.org/content/repositories/snapshots/' url "http://repo1.maven.org/maven2" } } dependencies { compile...

Get the Git Working Branch in Gradle on Jenkins


git,jenkins,gradle
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...

Exclude Package From Gradle Dependency


java,web-services,rest,gradle
I'm experiencing an issue where multiple versions of the same class are showing up in my classpath. The class in question is javax.ws.rs.core.UriBuilder. The version I want to use is brought in by javax.ws.rs:javax.ws.rs-api:2.0.1. However, we also use the Jira rest client library which has a dependency on the older...

Proguard - also use proguard files from modules


android,android-studio,gradle,proguard,android-proguard
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'), 'proguard-rules.pro' } } } dependencies { compile project(':androKnife') } And my androKnife module does have it's own...

How to create different build variants pointing to different Servers?


android,gradle
I am using gradle.build 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...

Can't use RecyclerView in my Android library project


android,gradle,dependencies,recyclerview,android-library
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: 'com.android.library' dependencies { compile 'com.android.support:recyclerview-v7:21.0.+' } Despite this, I cannot import RecyclerView in any java file; it even does not show up in the code completions popup...

How to elegantly build selected parts of a project


gradle
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....

duplicate an android studio project


android,gradle,duplicates,project,sync
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...

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


android,command-line,gradle
This question already has an answer here: Why won't gradle run from within a jenkins job 2 answers After following instructions here: http://developer.android.com/tools/building/building-cmdline.html 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...

Android Studio and gradle


android,android-studio,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...

Gradle : Stackoverflow Error


gradle,stack-overflow
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. ...

Adding Android AppWidget just for one Product Flavor


android,gradle,android-appwidget,android-productflavors
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...