简体   繁体   English

gradlew:如果 gradle 版本不一致会发生什么错误

[英]gradlew: What wrong can happen if gradle versions is not consistent

I am new to gradle.我是 gradle 的新手。 But I do understand to some extent why developers are encouraged to use gradlew instead of gradle.但我确实在某种程度上理解为什么鼓励开发人员使用 gradlew 而不是 gradle。 However what worse could happen if developers use different versions of gradle to build their project?但是,如果开发人员使用不同版本的 gradle 来构建他们的项目,会发生什么更糟糕的情况呢? At the end of the day any gradle version makes sure that dependencies of the project is managed properly.在一天结束时,任何 gradle 版本都会确保项目的依赖项得到正确管理。 For example if a Spring Boot project is dependent of a starter plugin version 2.x, no matter what version of gradle is used, the build tool makes sure that 2.x is available例如,如果一个 Spring Boot 项目依赖一个 starter plugin 版本 2.x,那么无论使用什么版本的 gradle,构建工具都会确保 2.x 可用

As far as I'm aware the main point to use a common version of Gradle is plugin compatibility.据我所知,使用通用版本的 Gradle 的要点是插件兼容性。

Gradle's internal APIs changed quite a lot in the last few versions, so not every plugin works with every Gradle version. Gradle 的内部 API 在最近几个版本中发生了很大变化,因此并非每个插件都适用于每个 Gradle 版本。

For example: Spring Boot's 2.3.4 reference explicitly states that it's build plugin requires Gradle 6.3 or later (although 5.6 is mentioned to work in a deprecated form)例如:Spring Boot 的 2.3.4 参考明确指出它的构建插件需要 Gradle 6.3 或更高版本(尽管提到 5.6 以不推荐的形式工作)

https://docs.spring.io/spring-boot/docs/2.3.x/reference/htmlsingle/#getting-started-system-requirements https://docs.spring.io/spring-boot/docs/2.3.x/reference/htmlsingle/#getting-started-system-requirements

So while you can be sure that the Spring Boot version is used (because you defined it in your buildfile) any older version of Gradle is likely to run into Exceptions when trying to build your project.因此,虽然您可以确定使用的是 Spring Boot 版本(因为您在构建文件中定义了它),但任何旧版本的 Gradle 在尝试构建您的项目时都可能遇到异常。

Even if you're just using plugins that are provided by Gradle itself there can be compatibility issues.即使您只是使用 Gradle 本身提供的插件,也可能存在兼容性问题。 For example the java configuration block was first introduced in Gradle 5 (I think) and therefore would cause a syntax error in earlier versions.例如,java 配置块最初是在 Gradle 5 中引入的(我认为),因此在早期版本中会导致语法错误。 Or simple things like Java versions that older version of Gradle do not support.或者简单的东西,比如旧版本的 Gradle 不支持的 Java 版本。

The more plugins you use it becomes increasingly unlikely that a lot of Gradle versions will be able to run it.您使用的插件越多,很多 Gradle 版本都无法运行它的可能性越来越大。 Using the Gradle Wrapper is therefore a simple way that your build works for everyone.因此,使用 Gradle Wrapper 是一种让您的构建适用于所有人的简单方法。

And from the other perspecitve: if you are the one that usually maintains the build you can use all the latest Gradle features using the Wrapper as you can be sure it will not break anything.从另一个角度来看:如果您是通常维护构建的人,您可以使用 Wrapper 使用所有最新的 Gradle 功能,因为您可以确保它不会破坏任何东西。 Getting everyone on the team to update manually before you can use a feature can be a pain让团队中的每个人在使用功能之前手动更新可能会很痛苦

That beeing said, it's really primarly a maintenance issue.蜜蜂说,这实际上主要是维护问题。 Nothing bad can happen if anyone uses their own installed version of gradle, except it might just not work If everyone on the team uses a similar version nothing might happen at all如果有人使用自己安装的 gradle 版本,则不会发生任何坏事,除非它可能无法正常工作如果团队中的每个人都使用类似的版本,则根本不会发生任何事情

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM