build.gradle解析
1 providedCompile、testImplementation、implementation、api、runtime、testCompile、classpath、natives
这些都是和plugin相关的,不同的plugin定义了不同的dependency configurations。
1.1 compileOnly和providedCompile的区别
compileOnly is only there for dependencies that you really don't need at runtime, e.g because you shade them inside your JAR or because they only contain some annotations that are only needed at compile time. That means if I depend on you, I should not need to provide those.
providedCompile on the other hand is a dependency that you do need at compile and runtime, but which you also declare is "to be provided by the app server", so it is removed from the WAR.
1.2 这些配置项和各个plugin是强相关的
2 什么是dependency configuration,有什么用
每个项目都会依赖于其它的jar包,所以需要指定dependency,但是不是指定了dependency就可以了的,根据情况还需要更加细化的配置,比如该dependency的jar包是不是要打包进war文件,等等。所以,不光需要设置dependency,还需要设置该dependency的configuration。
3 transitive dependency
假如我的project中依赖于Hibernate,那么Hibernate就是我的dependency,而Hibernate自己也是由dependencies的,这些dependencies就是我的transitive dependency。transitive dependency是由gradle自动负责的,假如出现问题,也可以自己进行控制。
4 gradle plugin
gradle本身只是一个平台,可以说一无是处,它什么也不会做,它将所具有的功能都是由gradle plugin提供的,比如编译java代码、c代码等的能力。
4.1 plugin为gradle定义了task
4.2 plugin可以进行配置
比如java plugin的配置source set、生成的jar包的存储目录等等。
4.3 dependency的configuration也是对gradle plugin的配置。
5 compile和runtime的区别
如下:
In the most common case, the artifacts needed at compile time are a subset of those needed at runtime. For example, let's say that a program called app uses library foo, and library foo internally uses library bar. Then only foo is needed to compile app, but both foo and bar are needed to run it. This is why by default, everything that you put on Gradle's compile configuration is also visible on its runtime configuration, but the opposite isn't true.
就是说,transitive dependencies是runtime的,而直接的dependencies是compile的。
一个jar包如果指定为compile的话,那么compile时需要,运行时也需要,那么gradle会把它编译进最终的生成文件中。这个还需要在实际项目中验证。
对于runtime的话,例子如下:
A common example is a JDBC driver, in which the application code is compiled against interfaces in the Java standard libraries, while the implementation is provided by a vendor. The java plug-in provides the runtime and testRuntime configurations for this purpose. These are used to create deployment archives and execute test code, but do not add to the compile-time classpath at all. The runtime configuration does contain the output of the compileJava task, of course, since a project’s .class files are necessarily required to run the project.
build.gradle解析的更多相关文章
- flutter_html  和 WebView  解析html  和 build.gradle源码
		
一.flutter_html 涉及的 api 接口: http://www.phonegap100.com/appapi.php?a=getPortalArticle&aid=20 二.Flu ...
 - 解析build.gradle文件
		
Gradle是一个非常先进的项目构建工具,它使用了一种基于Groovy的领域特定语言DSL来声明项目设置,摒弃了传统XML(如Ant和Maven)的各种繁琐配置 项目结构如上图: 1.最外层目录下的b ...
 - Could not find com.android.tools.build:gradle:1.3.0.
		
* What went wrong: A problem occurred configuring project ':TZYJ_Android'.> Could not re ...
 - Android(java)学习笔记126:Android Studio中build.gradle简介
		
1.首先我们直接上代码介绍: // Top-level build file where you can add configuration options common to all sub-pro ...
 - Android(java)学习笔记66:Android Studio中build.gradle简介
		
1.首先我们直接上代码介绍: // Top-level build file where you can add configuration options common to all sub-pro ...
 - 【转载】Gradle for Android 第二篇( Build.gradle入门 )
		
理解Gradle脚本 当然我们现在讨论的所有内容都是基于Android studio的,所以请先行下载相关工具.当我们创建一个新的工程,Android studio会默认为我们创建三个gradle文件 ...
 - 解决 Could not find com.android.tools.build:gradle 问题
		
今天拉同事最新的代码,编译时老是报如下错误: Error:Could not find com.android.tools.build:gradle:2.2.0.Searched in the fol ...
 - build.gradle文件介绍
		
对于以前用Eclipse开发安卓的小伙伴来说,Gradle文件是陌生的. 不同于Eclipse,而Android Studio 是采用Gradle来构建项目的. 先来介绍最外层目录下的build.gr ...
 - 怎么将Android studio 的“ build:gradle改低一点”
		
参考来源:http://bbs.qcloud.com/thread-17193-1-1.html Error:Execution failed for task ':xxxx:compileDebug ...
 
随机推荐
- [转载]在网页中插入media,RealPlayer等控件
			
[转载]在网页中插入media,RealPlayer等控件 (2012-11-02 20:27:43) 转载▼ 标签: 转载 原文地址:在网页中插入media,RealPlayer等控件作者:Mo ...
 - 记录一次通过命令行方式来使用svn碰到的一系列问题
			
由于使用Xcode自带的svn管理碰到很多问题,搞得头昏脑胀,找资料时看到小码哥这方面的视频,看完就开始折腾了. 准备:1.远程仓库地址及授权账号(用户名和密码) 2.一份项目代码,之所以要有这份代码 ...
 - ssh架包下载地址
			
1.连接MySQL数据库所需架包点击进入官网下载 2.连接Oracle数据库所需架包点击进入官网下载 3.JUnit测试所需架包点击进入官网下载或者点击进入官网下载 4.Struts所需架包点击进入官 ...
 - 扫黑除恶Team第四次团队作业
			
二.博客撰写要求 文章开头给出团队序号,开发的软件名称,仓库地址. 给出完成本次冲刺需要做的事情(Sprint Backlog)及相应说明. 本次冲刺总结. 三.评分规则 注意:本次作业总分61分.发 ...
 - Go:面向"对象"
			
一.封装 封装的实现步骤: 将结构体.字段的首字母小写(不能被导出): 给结构体所在的包提供一个工厂模式的函数,首字母大写.类似一个构造函数: 提供一个首字母大写的方法,由于获取结构体属性的值. 二. ...
 - 集训第五周 动态规划 B题LIS
			
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Des ...
 - <c:foreach> 标签获取循环次数
			
<c:forEach var="i" begin="1" end="9" varStatus="status"&g ...
 - Git和SVN共存的方法
			
刚工作的时候都是用的cvs和svn,对git不熟悉,随着工作的需要,打分支和版本管理的需要,熟悉起来了git,这一用不可收拾,比svn远远好用,尤其是版本分支管理上,切换分支的方便性,现在这家公司还是 ...
 - jQuery入门--- 非常好
			
jQuery入门------https://blog.csdn.net/dkh_321/article/details/78093788
 - 【spring boot 系列】spring data jpa 全面解析(实践 + 源码分析)
			
前言 本文将从示例.原理.应用3个方面介绍spring data jpa. 以下分析基于spring boot 2.0 + spring 5.0.4版本源码 概述 JPA是什么? JPA (Java ...