Gradle实现Maven中的dependencyManagement

本文介绍了如何在Gradle中模仿Maven的dependencyManagement,通过创建一个项目,配置java-platform和maven-publish插件,管理依赖并打包成POM文件发布到Maven私服。使用implementation platform或enforcedPlatform引入依赖管理,实现版本统一管理。
摘要由CSDN通过智能技术生成

在Maven中,我们可以通过dependencyManagement把Jar包版本进行统一管理,以后各项目引用组件时,就不用标注组件的版本号了。这为解决多项目版本冲突问题带来了很大的便利。

那么在Gradle中,是否也可以实现Maven的这个特性呢?答案是肯定的。看了网上的一些资料,发现有些方法比较绕,感觉思路不是很对。其实在官网上就有介绍这个问题,在这里也和大家再做一个分享。

1)创建一个项目,里面只需一个build.gradle文件即可。待会我们把要管理的依赖及其版本都封装到这个gradle脚本中,最后把它打包成POM文件,发布到Maven私服中。

build.gradle需要先引用java-platformmaven-publish插件;然后在dependencies的constraints方法里,配置要统一管理的依赖(这里以hutool-core的5.7.14版为例);最后在publishing方法里,配置POM文件的GAV坐标信息,以及Maven私服的信息。

2)脚本配置完成后,IDEA的Gradle Task面板中,就会出现我们刚才配置的发布任务。我们选择把它发布到Maven私服中

Learn how to use Gradle's powerful dependency management through extensive code samples, and discover how to define, customize, and deploy dependencies About This Book Be in total control of your dependencies Deploy your artifacts to repositories with Gradle Learn through code snippets and real-life examples Who This Book Is For If you work on Java projects, use Gradle as a build automation tool, and you use dependencies in your project, this is the book for you. Additionally, if you want to deploy your project artifacts as dependencies for other developers using Gradle, you've found the right book. In Detail Gradle is the next generation in build automation. It allows you to define dependencies for your project in a clear way and also customize how they are resolved to suit your needs. It offers fine-grained control over how to publish your artifacts to Maven and Ivy repositories. Gradle Dependency Management defines dependencies for your Java-based project and customizes how they are resolved. You will learn how to configure the publication of artifacts to different repositories. Packed with plenty of code samples, you will understand how to define the repositories that contain dependencies. Following this, you will learn how to customize the dependency resolution process in Gradle. Table of Contents Chapter 1. Defining Dependencies Chapter 2. Working with Repositories Chapter 3. Resolving Dependencies Chapter 4. Publishing Artifacts Chapter 5. Publishing to a Maven Repository Chapter 6. Publishing to Bintray Chapter 7. Publishing to an Ivy Repository
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值