簡體   English   中英

Android 依賴配置

[英]Android Dependency configurations

我一直在閱讀Gradle 文檔,以了解有關 Gradle 如何管理 Android 項目中的依賴項的更多信息。

最后,我了解 Java 庫插件決定如何使用以下配置構建和運行項目。

  • api
  • 執行
  • 只編譯
  • 僅運行時

但是,我正在嘗試使用 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>

問題

  1. 如何使用遠程庫而不是子模塊檢查配置之間的差異。
  2. pom.xml如何知道它的配置依賴關系?
  3. 也許 OkHttp 不是最好的例子,有沒有更好的解釋這個問題?

有人可以幫我一把嗎? 如果需要,我可以提供更多詳細信息。 或者我可以支付支持哈哈。

您的 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 配置(例如implementationapi ......)。

看看這個以便比較它們:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM