渐变安装提供不同的渐变版本



作为一名新用户,我试图在mac上安装gradle-5.6.4,但当我检查gradle版本时,它显示gradle 7.0。是否有任何东西可以将版本控制切换或更正为渐变。

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文件夹,它被生成并显示>grade.caches>7.0,如果它指向Gradle 7.0。我也尝试过删除这个,但得到了自动生成。

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

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

检查PATH环境变量的值,看看其他Gradle安装可能已经是其中的一部分。

echo $PATH

我敢肯定你会发现gradle 7.0的gradle命令已经在路上了。您可以编辑PATH或提供调用Gradle5.6.4的完整路径,但最好的做法是在您的项目中使用Gradle包装器来强制Gradle版本为您所知道的适用于您的项目的版本。

请注意,"gradlew"不是Gradle的一部分,它是添加到一些基于Gradle的单独项目中的包装脚本。

最新更新