gradle中 provided和compile区别

本文详细解释了在软件项目中使用provided依赖的意义。它指出provided依赖主要用于编译阶段,并且不会被打包进最终的应用程序中。此外,还介绍了如何处理本地与远程提供的jar包,并强调了在特定情况下使用aar格式的优势。

provided是指编译的时候依赖这个jar包,但是最终打包的时候不打进去

compile所指编译内容可以是本地的,也可以是远程(jCenter)中的。如果是本地的包,最好以aar形式给出。编译完成后jar包会被打包进入apk中。

### Build Script Formats in Gradle Build scripts in Gradle can be written using two different formats: `build.gradle` (Groovy-based) and `build.gradle.kts` (Kotlin DSL). Both serve the same purpose of configuring a project's build process but differ significantly in syntax and some features. #### Syntax Differences The Groovy-based script (`build.gradle`) uses a dynamic language with more concise syntax that is familiar to Java developers due to its widespread use within the ecosystem. For instance, applying plugins or defining dependencies looks like this: ```groovy // Applying plugin in Groovy apply plugin: 'java' dependencies { implementation 'org.example:some-library:1.0' } ``` On the other hand, Kotlin DSL scripts (`build.gradle.kts`) leverage modern programming constructs from Kotlin while still maintaining compatibility with existing Gradle APIs. The equivalent configuration would appear as follows: ```kotlin plugins { java } dependencies { implementation("org.example:some-library:1.0") } ``` This difference showcases how Kotlin DSL offers type safety through static typing along with better tooling support such as IDE autocompletion[^1]. #### Type Safety and Tool Support One significant advantage of using Kotlin DSL over traditional Groovy scripting lies in enhanced compile-time checks provided by Kotlin’s statically typed nature. This reduces runtime errors caused by misconfigurations since issues are caught during compilation rather than execution time. Additionally, improved integration between IntelliJ IDEA and Android Studio enhances productivity when working on projects utilizing these tools. #### Interoperability Between Scripts Despite their syntactical disparities, both types of files coexist peacefully within multi-module builds without requiring any special handling beyond ensuring consistent configurations across modules. However, mixing them might lead to maintenance challenges down the line because each dialect has unique idioms best suited for specific scenarios[^3]. #### Performance Considerations When it comes to performance aspects related specifically to parsing speed or memory consumption, there should not be noticeable differences between `.gradle` versus `.gradle.kts`. More impactful factors influencing overall efficiency include caching strategies employed via settings files alongside leveraging profiling capabilities offered by dedicated utilities like **Gradle Profiler**, which helps identify bottlenecks effectively.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

闲暇部落

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值