The CompileOptions.bootClasspath property has been deprecated

19.1k views Asked by At

After upgrading to Gradle 4.x, I get the warning

The CompileOptions.bootClasspath property has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the CompileOptions.bootstrapClasspath property instead.

in one of my projects. I don't see anything called bootClasspath or similar in my build.gradle. What does this warning mean?

the warning only appears in the commons subproject, not in core.

commons/build.gradle:

apply plugin: 'com.android.library'

ext {
    PUBLISH_GROUP_ID = 'com.afollestad.material-dialogs'
    PUBLISH_ARTIFACT_ID = 'commons'
    PUBLISH_VERSION = '0.9.2.3'
    BUILD_TOOLS = "26.0.3"
    TARGET_SDK = 25
}

android {
    compileSdkVersion TARGET_SDK
    buildToolsVersion BUILD_TOOLS

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion TARGET_SDK
        versionCode 1
        versionName PUBLISH_VERSION
    }
    lintOptions {
        checkReleaseBuilds false
    }
}

dependencies {
    implementation project(':core')
}

// Changes to this block must be applied in core/build.gradle and commons/build.gradle
task("javadoc", type: Javadoc) {
    description "Generates Javadoc API documentation for the main source code."
    source = android.sourceSets.main.java.srcDirs
    ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
    classpath += files(ext.androidJar)
    exclude "**/BuildConfig.java"
    exclude "**/R.java"
    options.links("http://docs.oracle.com/javase/7/docs/api/");
    options.links("http://d.android.com/reference/");
}

core/build.gradle:

apply plugin: 'com.android.library'

ext {
    PUBLISH_GROUP_ID = 'com.afollestad.material-dialogs'
    PUBLISH_ARTIFACT_ID = 'core'
    PUBLISH_VERSION = '0.9.2.3'
    SUPPORT_LIBRARY_VERSION = '25.4.0'
    BUILD_TOOLS = "26.0.3"
    TARGET_SDK = 25
}

android {
    compileSdkVersion TARGET_SDK
    buildToolsVersion BUILD_TOOLS

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion TARGET_SDK
        versionCode 1
        versionName PUBLISH_VERSION
        consumerProguardFiles 'progress-proguard.txt'
    }
    lintOptions {
        checkReleaseBuilds false
    }
}

dependencies {
    api "com.android.support:support-v13:$SUPPORT_LIBRARY_VERSION"
    api "com.android.support:appcompat-v7:$SUPPORT_LIBRARY_VERSION"
    api "com.android.support:recyclerview-v7:$SUPPORT_LIBRARY_VERSION"
    api "com.android.support:support-annotations:$SUPPORT_LIBRARY_VERSION"
    implementation "me.zhanghai.android.materialprogressbar:library:1.4.1"
}

// Changes to this block must be applied in core/build.gradle and commons/build.gradle
task("javadoc", type: Javadoc) {
    description "Generates Javadoc API documentation for the main source code."
    source = android.sourceSets.main.java.srcDirs
    ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
    classpath += files(ext.androidJar)
    exclude "**/BuildConfig.java"
    exclude "**/R.java"
    options.links("http://docs.oracle.com/javase/7/docs/api/");
    options.links("http://d.android.com/reference/");
}
3

There are 3 answers

1
Simon Warta On BEST ANSWER

My Gradle is using OpenJDK 8 from /usr/lib/jvm/java-8-openjdk-amd64/jre on Ubuntu (see by adding println System.getProperty("java.home") in build.gradle. No Android Studio involved.

I can trigger the the warning by explicitly setting sourceCompatibility and targetCompatibility to 1.7 (the default value). By changing the Java version to

android {

    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }
}

the warning disappears.

The reason why the warning is shown for only one project is that it is not repeated. commons is configured before core because of alphanumerical ordering. When I set sourceCompatibility and targetCompatibility to 1.8 for commons, the warning moves to core.

Setting sourceCompatibility and targetCompatibility to 1.8 for all projects removes the warning entirely. If this is what you want for your project and why Gradle 4 cannot be used warning-free with 1.7 are two separate questions.

1
AudioBubble On

I think this message about java Classpath and old JDK, adding this to your gradle will solve it:

android {

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

It's recommended to use java 9 JDK and uninstall old one then include it to your project structure: File -> Other settings -> Default project structure.

enter image description here

Possible conclusion:

Default JDK for android-studio is ...\Android studio\jre (The embedded JDK) as shown in above image. This embedded JDK contain the deprecated bootClasspath.

Using the new JDK which contain bootstrapClasspath or modify your compileOptions will solve it.

Why the old JDK (Embedded one) not compatible with new gradle version?

I have no idea.

0
will On

The foregoing aside, I can offer-up where the error arises for a Java build. The referenced: CompileOptions.bootClasspath must point to a Java run-time JAR matching the intended target system. That means, for example, if you are compiling to run your program on a server using Java 6, you need to set the bootClasspath to point at a compatible Java6 runtime, viz.: rt.jar

I normally set-up a project variable / environment variable to point to this file:

  • BOOT_CLASSPATH

It normally lives with the JRE, not in the JDK except under the jre folder.

In the project Gradle script, we have:

[compileJava, compileTestJava, ]*.options*.bootClasspath = BOOT_CLASSPATH

Set explicitly. However in some other scripts, we don't set the bootClasspath overtly at all, and still have the message in question.

The CompileOptions.bootClasspath property has been deprecated
and is scheduled to be removed in Gradle 5.0. Please use the    
CompileOptions.bootstrapClasspath property instead.

... anyway. I thusly surmise that the Java plugin is doing that itself as some default behaviour. I realise that's only background story. I may assist resolving the warning.

CompileOptions.bootstrapClasspath`