【问题标题】:The CompileOptions.bootClasspath property has been deprecatedCompileOptions.bootClasspath 属性已被弃用
【发布时间】:2018-05-09 18:07:24
【问题描述】:

升级到 Gradle 4.x 后,我get the warning

CompileOptions.bootClasspath 属性已被弃用,并计划在 Gradle 5.0 中删除。请改用 CompileOptions.bootstrapClasspath 属性。

在我的一个项目中。我的build.gradle 中没有看到任何名为bootClasspath 或类似名称的内容。这个警告是什么意思?

警告仅出现在 commons 子项目中,而不出现在 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/");
}

核心/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/");
}

【问题讨论】:

    标签: android gradle build.gradle android-gradle-3.0


    【解决方案1】:

    我的 Gradle 在 Ubuntu 上使用来自 /usr/lib/jvm/java-8-openjdk-amd64/jre 的 OpenJDK 8(请参阅在 build.gradle 中添加 println System.getProperty("java.home")。不涉及 Android Studio。

    我可以通过将sourceCompatibilitytargetCompatibility 显式设置为1.7(默认值)来触发警告。通过将 Java 版本更改为

    android {
    
        compileOptions {
            sourceCompatibility 1.8
            targetCompatibility 1.8
        }
    }
    

    警告消失。

    警告只显示一个项目的原因是它没有重复。由于alphanumerical orderingcommons 配置在core 之前。当我将sourceCompatibilitytargetCompatibility 设置为commons 的1.8 时,警告将移至core

    将所有项目的 sourceCompatibilitytargetCompatibility 设置为 1.8 会完全删除警告。如果这是您对项目的要求,以及为什么 Gradle 4 不能无警告地与 1.7 一起使用是两个独立的问题。

    【讨论】:

    • 找不到方法compileOptions()
    【解决方案2】:

    我认为这条关于 java Classpath 和旧 JDK 的消息,将其添加到您的 gradle 将解决它:

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

    建议使用 java 9 JDK 并卸载旧版本,然后将其包含到您的项目结构中:File -> Other settings -> Default project structure

    可能的结论:

    android-studio 的默认 JDK 为 ...\Android studio\jre(嵌入式 JDK),如上图所示。此嵌入式 JDK 包含已弃用的 bootClasspath

    使用包含bootstrapClasspath的新JDK或修改compileOptions即可解决。

    为什么旧的 JDK(嵌入式)与新的 gradle 版本不兼容?

    我不知道。

    【讨论】:

    • 感谢您为我指明正确的方向。我根据您的建议写了一个更详细的答案,其中遗漏了任何不适合我的环境的 JDK 9 解决方案。
    【解决方案3】:

    除了上述之外,我可以提供Java 构建出现错误的地方。引用的:CompileOptions.bootClasspath 必须指向与预期目标系统匹配的 Java 运行时 JAR。这意味着,例如,如果您正在编译以在使用 Java 6 的服务器上运行程序,则需要将 bootClasspath 设置为指向 兼容 Java6 运行时,即: rt.jar

    我通常设置一个项目变量/环境变量来指向这个文件:

    • BOOT_CLASSPATH

    它通常与 JRE 一起存在,而不是在 JDK 中,除非在 jre 文件夹下。

    在项目 Gradle 脚本中,我们有:

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

    明确设置。但是在其他一些脚本中,我们根本没有公开设置bootClasspath,并且仍然有问题的消息。

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

    ... 无论如何。因此,我推测 Java 插件本身就是作为一些默认行为这样做的。我意识到这只是背景故事。我可以协助解决警告。

    CompileOptions.bootstrapClasspath`

    【讨论】:

      猜你喜欢
      • 2021-04-30
      • 1970-01-01
      • 2017-03-12
      • 1970-01-01
      • 1970-01-01
      • 2020-05-05
      • 2020-03-06
      • 2012-11-06
      • 2019-04-04
      相关资源
      最近更新 更多