为什么会发布失败?

来源:4-11 实战:发布与使用-2

逐梦稚者

2021-03-19

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:router-annotations:compileJava’.

Could not find tools.jar. Please check that /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home contains a valid JDK installation.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use ‘–warning-mode all’ to show the individual deprecation warnings.
See https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 781ms
1 actionable task: 1 executed
innocentyang@192 Learn % java -version
java version "1.8.0_261"
Java™ SE Runtime Environment (build 1.8.0_261-b12)
Java HotSpot™ 64-Bit Server VM (build 25.261-b12, mixed mode)
innocentyang@192 Learn %

发布失败的提示信息是说找不到tool.jar?看不懂是哪里出了问题。
maven-publish.gradle完全是照着视频抄的,应该也没抄错:

apply plugin: "maven" // 使用maven插件中的发布功能

// 公共参数
Properties gradleProperties = new Properties()
gradleProperties.load(project.rootProject.file("gradle.properties").newDataInputStream())
def VERSION_NAME = gradleProperties.getProperty("VERSION_NAME")
def POM_URL = gradleProperties.getProperty("POM_URL")
def GROUP_ID = gradleProperties.getProperty("GROUP_ID")

// 子工程
Properties projectGradleProperties = new Properties()
projectGradleProperties.load(project.file("gradle.properties").newDataInputStream())
def POM_ARTIFACT_ID = projectGradleProperties.getProperty("POM_ARTIFACT_ID")

println("maven-publish VERSION_NAME = " + VERSION_NAME)
println("maven-publish POM_URL = " + POM_URL)
println("maven-publish GROUP_ID = " + GROUP_ID)
println("maven-publish POM_ARTIFACT_ID = " + POM_ARTIFACT_ID)

uploadArchives {
    repositories {
        mavenDeployer {
            // 填入发布信息
            repository(url: uri(POM_URL)) {
                pom.groupId = GROUP_ID
                pom.version = VERSION_NAME
                pom.artifactId = POM_ARTIFACT_ID
            }

            pom.whenConfigured { pom ->
                pom.dependencies.forEach { dep ->
                    if (dep.getVersion() == "unspecified") {
                        dep.setGroupId(GROUP_ID)
                        dep.setVersion(VERSION_NAME)
                    }
                }
            }
        }
    }
}

请老师帮忙看看是哪里写错了?

写回答

1回答

allenfeng

2021-03-19

可以检查下JDK是否已经正确安装,并且配置了JAVA_HOME等环境变量

0
4
逐梦稚者
回复
allenfeng
手动复制 tools.jar,下面第一个路径改为第一步获取的自己的路径 sudo cp /Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/lib/tools.jar /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib ———————————————— 版权声明:本文为CSDN博主「吞石鱼」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/qq_38735649/article/details/110820095 用这种方式搞定了.
2021-03-19
共4条回复

Android 应用程序构建实战+原理精讲

深度掌握 Gradle 使用,系统性学习 Android 应用构建知识

450 学习 · 116 问题

查看课程