通过pom文件
举个例子:
我们新建一个module,看一下依赖:
dependencies {
implementation “org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version”
implementation ‘androidx.core:core-ktx:1.3.2’
implementation ‘androidx.appcompat:appcompat:1.2.0’
implementation ‘com.google.android.material:material:1.2.1’
testImplementation ‘junit:junit:4.+’
androidTestImplementation ‘androidx.test.ext:junit:1.1.2’
androidTestImplementation ‘androidx.test.espresso:espresso-core:3.3.0’
}
利用maven plugin 进行发布,会有任务生成pom文件,如下:
<?xml version="1.0" encoding="UTF-8"?><project xsi:schemaLocation=“http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd” xmlns=“http://maven.apache.org/POM/4.0.0”
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”>
4.0.0
leobert
B
1.0.0
aar
org.jetbrains.kotlin
kotlin-stdlib
1.4.21
compile
androidx.core
core-ktx
1.3.2
compile
androidx.appcompat
appcompat
1.2.0
compile
com.google.android.material
material
1.2.1
compile
我们发现,关于测试相关的依赖并没有被收录到pom文件中。这很合理,测试代码是针对该module的,并不需要提供给使用方,其依赖自然也不需要传递。我们知道,AGP中现在有4种声明依赖的方式(除去testXXX这种变种)
-
api
-
implementation
-
compileOnly
-
runtimeOnly
runtimeOnly对应以前的apk方式声明依赖,我们直接忽略掉,测试一下生成的pom文件。
dependencies {
api “org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version”
implementation ‘androidx.core:core-ktx:1.3.2’
compileOnly ‘androidx.appcompat:appcompat:1.2.0’
compileOnly ‘com.google.android.material:material:1.2.1’
testImplementation ‘junit:junit:4.+’
androidTestImplementation ‘androidx.test.ext:junit:1.1.2’
androidTestImplementation ‘androidx.test.espresso:espresso-core:3.3.0’
}
<?xml version="1.0" encoding="UTF-8"?>&