`

How to use provided scope for jar file in Gradle build?

阅读更多

依赖包有时候会有重复,有时候会导致冲突

maven scope有provided属性,不会导致依赖和大型框架自带的一些jar包冲突

 

gradle也有几种scope:

Gradle compile:

如果你的jar包/依赖代码 在编译的时候需要依赖,在运行的时候也需要,那么就用compile
例如 :

compile 'org.springframework:spring-webmvc:4.3.9.RELEASE'

  

前提:apply plugin: 'war'或者apply plugin: 'java'

 

Gradle providedCompile:

如果你的jar包/依赖代码 仅在编译的时候需要,但是在运行时不需要依赖,就用providedCompile
例如:

compileOnly group: 'javax.servlet.jsp.jstl', name: 'jstl', version: '1.2'

 

前提:apply plugin: 'war'

 

Gradle runtime:

如果你的jar包/依赖代码 仅在运行的时候需要,但是在编译时不需要依赖,就用runtime
例如:

runtime group: 'mysql', name: 'mysql-connector-java', version: '5.1.42'

 

前提:apply plugin: 'java'

 

以上所说的前提,如果不正确配置的话,就会遇到依赖包无法导入,以及runtime以及providedCompile无法使用的情况。

高版本gradle没有了providedCompile

 

参考:https://stackoverflow.com/questions/18738888/how-to-use-provided-scope-for-jar-file-in-gradle-build

 

分享到:
评论

相关推荐

    Android studio 配置gradle 2.3.3 插件所需pom、jar文件

    取消勾选"Use default Gradle wrapper",然后在"Gradle home"中指定你下载的Gradle 2.3.3的安装路径。 2. **同步项目**:保存设置后,Android Studio会提示你同步项目。点击"Sync Now",系统将使用新版本的Gradle...

    Android studio 配置gradle 2.2.3 插件所需pom、jar文件

    3. **同步Gradle**:完成上述配置后,点击Android Studio中的"File" -> "Sync Project with Gradle Files",让Android Studio下载并应用新的Gradle版本。 4. **处理依赖**:在模块级别的`build.gradle`文件中,你...

    gradle将多模块打包成一个jar执行类demo

    标题中的“gradle将多模块打包成一个jar执行类demo”指的是使用Gradle构建工具将一个包含多个子模块的项目打包成一个可执行的JAR文件。在Java开发中,多模块项目通常是为了实现模块化设计,提高代码的可复用性和可...

    Gradle.Dependency.Management.1784392782

    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 ...

    Gradle Recipes for Android Master the New Build System for Android pdf 0分

    根据提供的文件内容,这本书名为《Gradle Recipes for Android Master the New Build System for Android》,由Ken Kousen所著。这本书专注于教授Android开发人员如何掌握Gradle这一新的构建系统。该书是O'Reilly ...

    gradle-trust-all.jar

    This plugin was born out of necessity for a quick-and-dirty way to use a Maven repository over HTTPS with a self-signed certificate. When working with such a repository in gradle you may get an error:...

    Android studio 配置gradle 2.2.2 插件所需pom、jar文件

    当您需要配置Android Studio以使用特定版本的Gradle插件时,例如2.2.2版本,您会遇到如标题和描述中提到的pom和jar文件。 1. **Gradle插件与版本管理**: Gradle插件是Gradle系统中可复用的构建逻辑单元,它们负责...

    Gradle.Essentials.1783982365

    Right from installing Gradle and writing your first build file to creating a fully-fledged multi-module project build, this book will guide you through its topics in a step-by-step fashion. ...

    gradle-4.1.1.jar

    gradle-4.1.1.jar

    Android studio 配置gradle 2.3.0 插件所需pom、jar文件

    2. **修改build.gradle文件**:在项目的根目录下的`build.gradle`文件中,你需要更新`buildscript`块内的`dependencies`部分,将Gradle插件版本更改为`2.3.0`,如下所示: ``` buildscript { repositories { ...

    build.gradle.zip

    首先,`build.gradle`是Gradle构建系统中的核心配置文件。Gradle是一种灵活且强大的构建自动化工具,广泛用于Java和其他JVM语言的项目。在这个文件中,开发者可以定义项目的依赖、任务、插件等配置,使得构建过程...

    gradle-wrapper.jar

    移动发开发,Java开发所需要的jar包,正确可以使用,方便好用

    Gradle-8.7-all最新版安装压缩包

    1.1 什么是Gradle? Gradle是一个开源构建自动化工具,专为大型项目设计。它基于DSL(领域特定语言)编写,该语言是用Groovy编写的,使得构建脚本更加简洁和强大。Gradle不仅可以构建Java应用程序,还支持多种语言和...

    Gradle Recipes for Android(O'Reilly,2016)

    This hands-on guide provides a collection of Gradle recipes to help you quickly and easily accomplish the most common build tasks for your Android apps. You’ll learn how to customize project layouts...

    gradle-8.7-bin

    4、什么是Gradle? Gradle是一个开源构建自动化工具,专为大型项目设计。它基于DSL(领域特定语言)编写,该语言是用Groovy编写的,使得构建脚本更加简洁和强大。Gradle不仅可以构建Java应用程序,还支持多种语言和...

    一个多module自动打包并合并成单个jar包的gradle插件,适合sdk模块化打包.zip

    例如,在`build.gradle`文件中,他们可能需要添加插件依赖,并配置插件以指定哪些模块或jar需要被打包到一起。此外,他们还可以定制化打包过程,比如排除某些不需要的资源或类,或者设置jar的元数据信息。 总的来说...

    Gradle for Android

    Using Gradle makes it easy for Android developers to manage dependencies and set up the entire build process., This book begins by taking you through the basics of Gradle and how it works with ...

    Gradle in Action

    Starting with the basics, this practical, easy-to-read book discusses how to establish an effective build process for a full-fledged, real-world project. Along the way, it covers advanced topics like...

Global site tag (gtag.js) - Google Analytics