0

I am trying out Hawk authentication by https://github.com/wealdtech/hawk. I would like to include this library by source in an empty project so that I can experiment with the apis. I do not want to use a jar or gradle dependency.

I import the project as a module and I run into this error:

Error:(2, 0) Gradle DSL method not found: 'compile()'
Possible causes:<ul><li>The project 'HawkTest' may be using a version of Gradle that does not contain the method.
<a href="open.wrapper.file">Open Gradle wrapper file</a></li><li>The build file may be missing a Gradle plugin.
<a href="apply.gradle.plugin">Apply Gradle plugin</a></li>

I tried solutions from these links but I could not derive any information that could help resolve this issue: Android gradle build Error:(9, 0) Gradle DSL method not found: 'compile()'.

Android gradle build Error:(9, 0) Gradle DSL method not found: 'compile()'.

I have spent many hours on this problem but do not seem anywhere near a solution. Any direction or a solution would be greatly appreciated.

This my top-level build file:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

The app level file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.test.android.hawktest"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
}

The Hawk module's gradle file:

dependencies {
    compile 'com.wealdtech:wealdtech-core:2.0.0'
    compile 'com.wealdtech:wealdtech-configuration:2.0.0'
    compile 'com.google.guava:guava:17.0'
}

uploadArchives {
    repositories {
        mavenDeployer {
            pom.project {
                pom.artifactId = 'hawk-core'
                name 'Hawk Core'
                description 'Java implementation of Hawk protocol - core'
            }
        }
    }
}

And my directory structure:

enter image description here

Community
  • 1
  • 1
user1841702
  • 2,683
  • 6
  • 35
  • 53

1 Answers1

0

hawk top level build.gradle contains all subproject configuration (check https://github.com/wealdtech/hawk/blob/develop/build.gradle)

For the whole process, from your project root directory :

git clone git@github.com:wealdtech/hawk.git

In your settings.gradle, this will configure the gradle modules :

include ':app',':hawk-core', ':hawk-server-jersey', ':hawk-client-jersey'
project(':hawk-core').projectDir = new File('hawk/hawk-core')
project(':hawk-server-jersey').projectDir = new File('hawk/hawk-server-jersey')
project(':hawk-client-jersey').projectDir = new File('hawk/hawk-client-jersey')

Then edit your top level build.gradle to specify the configuration for the Java project. Add the following :

configure(subprojects.findAll {it.name.startsWith('hawk')}) {

    apply plugin: 'java'
    apply plugin: 'maven'
    apply plugin: 'idea'
    apply plugin: 'signing'

    repositories {
        mavenCentral()
        mavenLocal()
    }

    dependencies {
        testCompile 'org.testng:testng:6.8'
    }

    task copyLibs (type: Copy) {
        into "$buildDir/output/libs"
        from configurations.testRuntime
    }

    task testJar (type: Jar) {
        classifier = 'tests'
        from sourceSets.test.output
    }

    task javadocJar(type: Jar, dependsOn: javadoc) {
        classifier = 'javadoc'
        from 'build/docs/javadoc'
    }

    task sourcesJar(type: Jar) {
        classifier = 'sources'
        from sourceSets.main.allSource
    }

    artifacts {
        archives jar
        archives javadocJar
        archives sourcesJar
    }

}

You cant add Java plugin (apply plugin: 'java') for your Android project . If you do so, you will have this error : The 'java' plugin has been applied, but it is not compatible with the Android plugins.. This is why I use the configure(subprojects.findAll and perform a filter on hawk modules. I've copied the remaining configuration from https://github.com/wealdtech/hawk/blob/develop/build.gradle

Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159