Search code examples
mavenjakarta-mailandroid-gradle-pluginbuild.gradlegmail-api

How to make dependency transitive in Gradle


I have downloaded javax.mail-api-1.5.3.jar file copied into app/libs folder and then right click , add as library. Then following line appears under dependency

compile files('libs/javax.mail-api-1.5.3.jar')

I want to make this dependency transitive.Because I have mention javax.mail-api library dependencies in pom.xml file like follows.

 <dependencies>
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>javax.mail-api</artifactId>
            <version>1.5.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.mail</groupId>
            <artifactId>javax.mail</artifactId>
            <version>1.5.3</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

I also tried

compile (files('libs/javax.mail-api-1.5.3.jar')){
    transitive true
}

then this error occurs.

    Error:(34, 0) Gradle DSL method not found: 'compile()'
    Possible causes:
The project 'MeetingManager' may be using a version of Gradle that does not contain the method.
    Open Gradle wrapper file 

The build file may be missing a Gradle plugin.
    Apply Gradle plugin

I don't no what to do next, Please help.

My build.Gradle file looks like

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.example.meetingmanager"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions{
        exclude 'META-INF/LICENSE.txt'
    }


}

dependencies {
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile 'com.google.android.gms:play-services:7.3.0'
    compile 'com.google.api-client:google-api-client:1.20.0'
    compile 'com.google.apis:google-api-services-gmail:v1-rev29-1.20.0'
    compile 'com.google.api-client:google-api-client-android:1.20.0'
    compile 'com.google.api-client:google-api-client-gson:1.20.0'
    compile (files('libs/javax.mail-api-1.5.3.jar')){
        transitive true
    }

}

Solution

  • The javax.mail-api-1.5.3 can also be downloaded from existing repositories (probably jCenter or mavenCentral) described in your build file. If you aren't tied to using your downloaded version in /libs, you might do this in your build file:

    dependency {
      compile 'javax.mail:javax.mail-api:1.5.3'
    }
    

    The default behavior in this case is to download transitive dependencies when you specify it like this.

    Here's a reference to that repository : http://mvnrepository.com/artifact/javax.mail/javax.mail-api/1.5.3