I've been reading the Gradle docs to learn more about how Gradle manage the dependencies in an Android project.
Finally I understand The Java Library Plugin decide how to build and run a project using the following configurations.
However I'm trying to check the differences of those configurations using android libraries as retrofit, glide or okHttp and I'm not able to find one. For example, let's say I want to try OkHttp.
Using API
api "com.squareup.okhttp3:okhttp:4.6.0"
Using implementation
implementation "com.squareup.okhttp3:okhttp:4.6.0"
I don't see any difference in Project -> External Libraries -> com.squareup.okhttp3
or using ./gradlew app:androidDependencies
I'm not sure if this configurations are only useful in a multimodule project, where its easier check the differences (at least api vs implementation).
If I go deeper in the OkHttp pom.xml
I don't know which configuration is used: 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
knows about its configurations dependencies?Could someone give me a hand? I can provide more details if needed. Or I can pay for support haha.
Your gradle project has the dependency Okhttp.
Okhttp is a maven project.
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.
If you look at the pom.xml
from OKhttp, you can see dependencies like this:
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-annotations</artifactId>
<version>1.17</version>
<scope>provided</scope>
</dependency>
The <scope>
is the maven equivalent to the gradle configuration (e.g. implementation
, api
,...).
Take a look at this in order to compare them:
Maven | Gradle |
---|---|
compile | compile |
provided | compileOnly, testCompileOnly (Gradle only) |
system (maven only, local JAR) | - |
runtime | runtime |
test | testCompile, testRuntime (Gradle only) |
The official documentation of scopes can be found here.
A remote library is a library that you just import in your project. It is uploaded to a repository like jcenter or maven central.
A submodule is a part of the project that is also located in the project. If the parent project is e.g. compiled, the submodule will be compiled too.