groovy / groovy-android-gradle-plugin

A Gradle plugin to support the Groovy language for building Android apps
Apache License 2.0
850 stars 116 forks source link

Extra groovy sources as per usage guidelines #111

Closed marcocamacho closed 8 years ago

marcocamacho commented 8 years ago

I followed the instructions to add groovy to an existing project by adding the sourceSets. Plug in versions are: com.android.tools.build:gradle:1.5.0 org.codehaus.groovy:gradle-groovy-android-plugin:0.3.8

Gradle and Groovy versions are: Gradle 2.10 Groovy: 2.4.4

build.gradle looks like this:

apply plugin: 'com.android.application'
apply plugin: 'groovyx.grooid.groovy-android'

android {
    compileSdkVersion 22
    buildToolsVersion 22.0.1

    defaultConfig {
        applicationId "com.xxx"
        minSdkVersion 19
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"

        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    testOptions {
        unitTests.returnDefaultValues = true
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }
}

androidGroovy {
    sourceSets {
        main {
            groovy {
                srcDirs += 'src/main/java'
            }
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.1.0'
    compile 'com.android.support:recyclerview-v7:22.1.0'
    compile 'com.android.support:cardview-v7:22.1.0'
    compile 'com.google.android.gms:play-services:8.1.0'
    compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
    compile 'com.android.support:design:22.2.0'
    compile 'org.codehaus.groovy:groovy:2.4.5:grooid'
}

The following error is displayed:

Caused by: org.gradle.api.internal.MissingMethodException: Could not find method groovy() for arguments [build_2zmtm6svt9eecujrd02le3y0e$_run_closure2$_closure11$_closure12$_closure13@149aa7b2] on source set 'main'.
        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:175)
        at org.gradle.api.internal.tasks.DefaultSourceSet_Decorated.invokeMethod(Unknown Source)
AndrewReitz commented 8 years ago
androidGroovy {
    sourceSets {
        main {
            groovy {
                srcDirs += 'src/main/java'
            }
        }
    }
}

This isn't available in plugin 0.3.8, it became available in 0.3.9