我一直在阅读Gradle文档,以了解Gradle如何管理Android项目中的依赖关系。
最终,我了解到Java Library插件使用以下配置来决定如何构建和运行一个项目。
- api - implementation - compileOnly - runtimeOnly
然而,我试图检查这些配置之间的差异,使用像retrofit、glide或okHttp这样的Android库,但是我没有找到其中的区别。例如,假设我想尝试OkHttp。
使用API
使用实现。
我看不出在
最终,我了解到Java Library插件使用以下配置来决定如何构建和运行一个项目。
- api - implementation - compileOnly - runtimeOnly
然而,我试图检查这些配置之间的差异,使用像retrofit、glide或okHttp这样的Android库,但是我没有找到其中的区别。例如,假设我想尝试OkHttp。
使用API
api "com.squareup.okhttp3:okhttp:4.6.0"
使用实现。
implementation "com.squareup.okhttp3:okhttp:4.6.0"
我看不出在
Project -> External Libraries -> com.squareup.okhttp3
或使用./gradlew app:androidDependencies
有任何区别。我不确定这些配置是否仅在多模块项目中有用,在这种情况下,检查差异更容易(至少是api vs implementation)。如果我深入研究OkHttp的pom.xml
,我不知道使用哪个配置:api
、implementation
、compileOnly
、runtimeOnly
。<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>parent</artifactId>
<version>3.14.7</version>
</parent>
<artifactId>okhttp</artifactId>
<name>OkHttp</name>
<dependencies>
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
</dependency>
<dependency>
<groupId>org.conscrypt</groupId>
<artifactId>conscrypt-openjdk-uber</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.robolectric</groupId>
<artifactId>android-all</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-annotations</artifactId>
<version>1.17</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>templating-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<goals>
<goal>filter-sources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<excludePackageNames>okhttp3.internal:okhttp3.internal.*</excludePackageNames>
<links>
<link>http://square.github.io/okio/</link>
</links>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<archive>
<manifestEntries>
<Automatic-Module-Name>okhttp3</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
问题
- 如何使用远程库而不是子模块来检查配置之间的差异。
pom.xml
如何知道其配置依赖关系?- 也许 OkHttp 不是最好的例子,有没有更好的例子来解释这些问题?
有人能帮帮我吗?如果需要,我可以提供更多细节。或者我可以付费获得支持哈哈。
api
和implementation
等价的内容,因此两者都应被视为已弃用的compile
,是吗? - Ricardo