[英]Android Dependency configurations
我一直在閱讀Gradle 文檔,以了解有關 Gradle 如何管理 Android 項目中的依賴項的更多信息。
最后,我了解 Java 庫插件決定如何使用以下配置構建和運行項目。
但是,我正在嘗試使用 android 庫作為 retrofit、glide 或 okHttp 檢查這些配置的差異,但我找不到。 例如,假設我想嘗試 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 與實現)。
如果我在 OkHttp pom.xml 中更深的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
如何知道它的配置依賴關系?有人可以幫我一把嗎? 如果需要,我可以提供更多詳細信息。 或者我可以支付支持哈哈。
您的 gradle 項目具有 Okhttp 依賴項。
Okhttp 是一個 maven 項目。
Gradle and maven are both build tools and they essentially do the same thing, the pom.xml
is the maven equivalent to the build.gradle
file.
如果您查看pom.xml
中的 pom.xml,您可以看到如下依賴項:
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-annotations</artifactId>
<version>1.17</version>
<scope>provided</scope>
</dependency>
<scope>
是 maven 等效於 gradle 配置(例如implementation
, api
......)。
看看這個以便比較它們:
maven - gradle
compile - compile
provided - compileOnly, testCompileOnly (only gradle)
system (maven only, local JAR)
runtime - runtime
test - testCompile, testRuntime
范圍的官方文檔可以在這里找到。
遠程庫是您只需在項目中導入的庫。 它被上傳到 jcenter 或 maven 中央等存儲庫。
子模塊是項目的一部分,也位於項目中。 例如,如果父項目被編譯,子模塊也將被編譯。
如果我忘記了什么,請隨時發表評論。 在這種情況下,我會嘗試編輯我的答案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.