【问题标题】:Gradle installation gives different gradle versionGradle 安装给出了不同的 gradle 版本
【发布时间】:2021-09-02 03:46:12
【问题描述】:

作为一个新用户,我试图在我的 Mac 上安装 gradle-5.6.4,但是当我检查 gradle 版本时,它显示 Gradle 7.0。有什么可以切换或更正版本控制到 gradle。

machine1:~ user$ cd /Users/user/Downloads/gradle-5.6.4/bin 
machine1:bin user$ gradle

Welcome to Gradle 7.0!

Here are the highlights of this release:
 - File system watching enabled by default
 - Support for running with and building Java 16 projects
 - Dependency catalog feature preview

For more details see https://docs.gradle.org/7.0/release-notes.html
Starting a Gradle Daemon (subsequent builds will be faster)
> Task :help
Welcome to Gradle 7.0.
To run a build, run gradle <task> ...
To see a list of available tasks, run gradle tasks
To see a list of command-line options, run gradle --help
To see more detail about a task, run gradle help --task <task>
For troubleshooting, visit https://help.gradle.org
BUILD SUCCESSFUL in 6s
1 actionable task: 1 executed

machine1:bin user$ 
machine1:bin user$ gradle wrapper --gradle-version 5.6.4
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
> Task :wrapper FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Some problems were found with the configuration of task ':wrapper' (type 'Wrapper').
  - Type 'Wrapper' property 'jarFile' is not writable because '/Users/user/Downloads/gradle-5.6.4/bin/gradle/wrapper/gradle-wrapper.jar' ancestor '/Users/user/Downloads/gradle-5.6.4/bin/gradle' is not a directory.
    
    Reason: Cannot write a file to a location pointing at a directory.
    
    Possible solution: Configure 'jarFile' to point to a file, not a directory.
    
    Please refer to https://docs.gradle.org/7.0/userguide/validation_problems.html#cannot_write_output for more details about this problem.
  - Type 'Wrapper' property 'propertiesFile' is not writable because '/Users/user/Downloads/gradle-5.6.4/bin/gradle/wrapper/gradle-wrapper.properties' ancestor '/Users/user/Downloads/gradle-5.6.4/bin/gradle' is not a directory.
    
    Reason: Cannot write a file to a location pointing at a directory. 
    Possible solution: Configure 'propertiesFile' to point to a file, not a directory.
    Please refer to https://docs.gradle.org/7.0/userguide/validation_problems.html#cannot_write_output for more details about this problem.
* 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

BUILD FAILED in 5s
1 actionable task: 1 executed
machine1:bin user$ 
machine1:bin user$ 
machine1:bin user$ ./gradlew build
-bash: ./gradlew: No such file or directory
machine1:bin user$ pwd
/Users/user/Downloads/gradle-5.6.4/bin
machine1:bin user$ ls
gradle      gradle.bat  settings.gradle

不确定 Gradle 7 是否被意外安装并覆盖到 gradle 5.6.4。不确定要遵循的正确步骤是什么。在我的 .bash_profile 中,我添加了以下内容:

export GRADLE_HOME=/Users/user/Downloads/gradle-5.6.4
export PATH=$PATH:$GRADLE_HOME/bin

还有一个 .gradle 文件夹,它会生成并在文件夹中显示 > .gradle.caches>7.0,如果它指向 Gradle 7.0。我也尝试将其删除,但会自动生成。

【问题讨论】:

  • 您将其添加到 PATH 环境变量的末尾,因此将在最后找到它。 PATH 中是否已经有另一个 Gradle 文件夹?

标签: java spring unix gradle


【解决方案1】:

运行这些命令时,您不在项目目录中。

从项目文件夹中运行 gradle 命令,而不是 Gradle 安装的 bin 文件夹。

检查 PATH 环境变量的值以查看其他 Gradle 安装可能已经包含在其中。

echo $PATH

我相当肯定你会发现 Gradle 7.0 的 gradle 命令已经在路径上。您可以编辑 PATH 或提供调用 Gradle 5.6.4 的完整路径,但最好的办法是在您的项目中使用 Gradle 包装器,将 Gradle 版本强制为您知道适合您的项目的版本。

请注意,“gradlew”不是 Gradle 的一部分,它是添加到某些基于 Gradle 的单个项目的包装脚本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-06
    • 1970-01-01
    • 2021-08-16
    • 1970-01-01
    • 2020-01-30
    • 1970-01-01
    相关资源
    最近更新 更多