`

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

 

分享到:
评论

相关推荐

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

    Gradle Recipes for Android Master the New Build System for Android 英文pdf

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

    gradle-4.1.1.jar

    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 in action

    Gradle in action 正式版 Part 1: Introducing Gradle Chapter 1. Introduction to project automation Chapter 2. Next-generation builds with Gradle Chapter 3. Building a Gradle project by example Part 2...

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

    build.gradle.zip

    kafka切换阿里云镜像配置文件build.gradle, 解决com.github.spotbugs报错问题。

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

    gradle将多模块打包成一个jar执行类demo,附博客地址:https://blog.csdn.net/qq_43813937/article/details/106869813

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

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

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

    Mastering.Gradle.178398136

    If you are a developer with some experience in build tool and want to become an expert in build tool, then this book is for you. Basic knowledge of Gradle or any other build tool is essential. What ...

    maven构建gradle的jar

    jar共享gradle-aspectj-1.6,maven构建gradle的jar,maven构建gradle的jar,maven构建gradle的jar。

    android studio 一直卡在Gradle:Build Running的几种解决办法

    在使用AS开发安卓应用程序的时候经常会遇到Gradle build running一直在运行甚至卡死的情况,解决方法如下: 方法1: 1、在C:\User\<用户名>\.gradle 目录下新建一个gradle.properties文件,并在里面添加一行:org...

    Mastering Gradle(PACKT,2015)

    With Gradle, you can efficiently build ... Finally, you will also learn how to create a simple mobile application using Android and explore how Gradle can help you to build and test the application.

    Android Studio、Gradle、Build Tools版本详细版本对照表

    内容包括:1.Android StudioRelease所有...3.Android Studio版本、Gradle版本、Build Tools版本详细对照,让大家不再因为版本问题而纠结,你只需要知道哪个Android Studio版本用对应Gradle以及Build Tools就可以了。

    Introducing Gradle(Apress,2015)

    It includes the new features and enhancements found in the latest version of Gradle, an open source enhanced Java build and release tool for Java that is especially popular among Spring application ...

    android gradle导出jar包,并包含assets资源文件夹

    本demo是结合博客的资源,如有不懂请去看博客 http://blog.csdn.net/u013895206 ,文章是:android 使用gradle导出jar包,并包含assets资源文件夹。谢谢!

    Gradle Essentials(PACKT,2015)

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

    Android Gradle Build Error:Some file crunching failed, see logs for details解决办法

    Android Gradle Build Error:Some file crunching failed, see logs for details解决办法 错误日志:Error:java.lang.RuntimeException: Some file crunching failed, see logs for details Log:  FAILURE: Build...

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

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

Global site tag (gtag.js) - Google Analytics