实现和编译在级别上有什么区别
After updating to Android Studio 3.0 and creating a new project, I noticed that in build.gradle
there is a new way to add new dependencies instead of compile
there is implementation
and instead of testCompile
there is testImplementation
.
在升级到Android Studio 3.0并创建一个新项目后,我注意到在构建中。有一种新的方法可以添加新的依赖项而不是编译,有实现,而不是testCompile,有testImplementation。
example:
例子:
implementation 'com.android.support:appcompat-v7:25.0.0'
testImplementation 'junit:junit:4.12'
instead of
而不是
compile 'com.android.support:appcompat-v7:25.0.0'
testCompile 'junit:junit:4.12'
What's the difference between them and what should I be using?
它们之间的区别是什么?我应该使用什么?
5 个解决方案
#1
650
It is one of the breaking changes coming with gradle:3.0 that Google announced at IO17 gradle:3.0
这是谷歌在IO17发布的3.0级的一个突破性变化
the compile
configuration is now deprecated and should be replaced by implementation
or api
现在不赞成编译配置,应该由实现或api替代
From the gradle docs :
从初级文档开始:
dependencies { api 'commons-httpclient:commons-httpclient:3.1' implementation 'org.apache.commons:commons-lang3:3.5' }
Dependencies appearing in the
api
configurations will be transitively exposed to consumers of the library, and as such will appear on the compile classpath of consumers.在api配置中出现的依赖项将临时公开给库的使用者,因此将出现在使用者的编译类路径中。
Dependencies found in the
implementation
configuration will, on the other hand, not be exposed to consumers, and therefore not leak into the consumers' compile classpath. This comes with several benefits:另一方面,在实现配置中发现的依赖项将不会被公开给使用者,因此不会泄漏到使用者的编译类路径中。这有几个好处:
- dependencies do not leak into the compile classpath of consumers anymore, so you will never accidentally depend on a transitive dependency
- 依赖项不再泄漏到使用者的编译类路径中,因此您永远不会偶然地依赖于传递依赖项
- faster compilation thanks to reduced classpath size
- 由于类路径大小减少,编译速度更快
- less recompilations when implementation dependencies change: consumers would not need to be recompiled
- 当实现依赖项发生变化时,重新编译的次数更少:不需要重新编译使用者
- cleaner publishing: when used in conjunction with the new maven-publish plugin, Java libraries produce POM files that distinguish exactly between what is required to compile against the library and what is required to use the library at runtime (in other words, don't mix what is needed to compile the library itself and what is needed to compile against the library).
- 使用时清洁出版:结合新maven-publish插件,Java库产生POM文件之间的区别到底是什么需要编译针对图书馆需要在运行时使用这个库是什么(换句话说,不要混合所需要编译库本身和所需要编译的库)。
The compile configuration still exists but should not be used as it will not offer the guarantees that the api and implementation configurations provide.
编译配置仍然存在,但是不应该使用,因为它不能提供api和实现配置提供的保证。
tl;dr
博士tl;
Just replace:
只是替换:
compile
withimplementation
- 编制与实施
testCompile
withtestImplementation
- 与testImplementation testCompile
debugCompile
withdebugImplementation
- 与debugImplementation debugCompile
androidTestCompile
withandroidTestImplementation
- 与androidTestImplementation androidTestCompile
compileOnly
is still valid. It was added in 3.0 to replace provided and not compile. (provided
introduced when Gradle didn't have a configuration name for that use-case and named it after Maven's provided scope.)- compileOnly仍然是有效的。它在3.0中被添加以取代提供的而不是编译。(当Gradle没有为那个用例提供配置名并以Maven提供的范围命名时引入)。
更多相关文章
- android中wifi输入的密码保存的路径
- android 打开系统相册得到路径 上传图片到php服务器
- 错误:警告:无法从javaldx读取路径
- java项目中Classpath路径到底指的是哪里?
- 如何将树路径转换为json对象
- Java - 获取ClassPath的路径和资源
- 在二叉树中找出和为某一值的所有路径-java实现
- ArcGIS JS API For JavaScript实现类台风运动路径与影响范围的显
- 蓝桥杯--第七届决赛:路径之谜