请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

为什么会发布失败?

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回答

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

0 回复 有任何疑惑可以回复我~
  • 提问者 逐梦稚者 #1
    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)
    
    在问题描述里里贴记录,发布失败后,立即调用了 java -version,JDK和环境变量正常配置。
    回复 有任何疑惑可以回复我~ 2021-03-19 11:53:11
  • 提问者 逐梦稚者 #2
    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)
    
    提问信息里有粘贴,在发布失败后立刻用JAVA -version命令,结果可以正常打印。
    回复 有任何疑惑可以回复我~ 2021-03-19 11:54:15
  • 添加 名为 JAVA_HOME 的环境变量,或者 找到当前用户目录下的 .gradle 目录下gradle.properties 文件,并在文件中输入如下内容:
    
    org.gradle.java.home=JDK路径
    回复 有任何疑惑可以回复我~ 2021-03-19 11:57:14
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信