Skip to content

Commit

Permalink
Switch from "compile" to "implementation" in gradle dependencies
Browse files Browse the repository at this point in the history
compile/testCompile has been deprecated for a long time, and will be
removed in the next major version of gradle.
  • Loading branch information
JesusFreke committed Mar 1, 2021
1 parent ecd6891 commit 53b52f0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 30 deletions.
17 changes: 9 additions & 8 deletions baksmali/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ buildscript {
}

dependencies {
compile project(':util')
compile project(':dexlib2')

This comment has been minimized.

Copy link
@iBotPeaches

iBotPeaches Mar 2, 2021

Contributor

hi @JesusFreke , I noticed trying to do the upgrade to v2.5.0 that I was forced to add dexlib2 (previously just baksmali/smali) - iBotPeaches/Apktool#2519

I think this was my fault, because after a quick research it appears that api is the old behavior of compile, but compile was leaking dependencies that it may use. So I used dexlib2, but only imported smali/baksmali. That failed with 2.5.0 until I explicitly brought in dexlib2.

I brought it in, so no issue - well still a build issue with java8 but I haven't figured it out yet. I just wanted to post this because I also swapped compile/implementation and thought they were equal.

This comment has been minimized.

Copy link
@JesusFreke

JesusFreke Mar 3, 2021

Author Owner

Yeah, I'm honestly not 100% sure what the difference is between them, but I also saw some slight differences.

This comment has been minimized.

Copy link
@Lanchon

Lanchon Mar 3, 2021

Contributor

the diff:

  1. api
    project B uses project A via "api" config
    project C uses project B
    then project C receives A as a compile-time and runtime dependency. project C can reference names in A.
    this is used when the public api of B references names in A.
    example: A is a vector lib and B is a matrix lib. some api of B takes or returns vectors.

  2. implementation
    project B uses project A via "implementation" config
    project C uses project B
    then project C receives A as a runtime dependency only. project C cannot reference names in A. A does not leak: names in A do not pollute the namespace of C. A is a B implementation detail. B can switch A for a different dependency without breaking any project depending on itself.
    this is used when the public api of B does not reference names in A.
    example: A is a vector lib and B uses vectors for internal calculations. no api of B takes or returns vectors.

I think this was my fault

no. compile to implementation is an api breaking change. (compile to api is not.) whether the breaking change was intended (to fix an unwanted leak of dexlib2) or accidental, i do not know.

if the public api of baksmali uses dexlib2 objects, then JF should change the config to api and CT should remove the redundant import of dexlib2.

This comment has been minimized.

Copy link
@JesusFreke

JesusFreke Mar 3, 2021

Author Owner

Thanks, I wasn't aware of the api configuration. I switched them over to depend on dexlib2 via an api dependency in v2.5.2.

compile depends.guava
compile depends.jcommander

testCompile depends.junit
testCompile project(':smali')
implementation project(':util')
implementation project(':dexlib2')
implementation depends.guava
implementation depends.jcommander

testImplementation depends.junit
testImplementation project(':smali')
testImplementation depends.antlr_runtime
}

processResources.inputs.property('version', version)
Expand All @@ -54,7 +55,7 @@ processResources.expand('version': version)
// Build a separate jar that contains all dependencies
task fatJar(type: Jar) {
from sourceSets.main.output
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }

classifier = 'fat'

Expand Down
10 changes: 5 additions & 5 deletions dexlib2/accessorTestGenerator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
*/

dependencies {
compile project(':util')
compile 'com.google.code.findbugs:jsr305:1.3.9'
compile 'com.google.guava:guava:13.0.1'
compile 'org.antlr:ST4:4.0.7'
implementation project(':util')
implementation 'com.google.code.findbugs:jsr305:1.3.9'
implementation 'com.google.guava:guava:13.0.1'
implementation 'org.antlr:ST4:4.0.7'

testCompile 'junit:junit:4.6'
testImplementation 'junit:junit:4.6'
}
8 changes: 4 additions & 4 deletions dexlib2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ configurations {
}

dependencies {
compile depends.findbugs
compile depends.guava
implementation depends.findbugs
implementation depends.guava

testCompile depends.junit
testCompile depends.mockito
testImplementation depends.junit
testImplementation depends.mockito

accessorTestGenerator project('accessorTestGenerator')

Expand Down
17 changes: 9 additions & 8 deletions smali/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ buildscript {
configurations {
// Remove the full antlr library that's added by the antlr plugin. We manually
// add the smaller antlr_runtime library instead
compile.exclude group: 'org.antlr', module: 'antlr'
implementation.exclude group: 'org.antlr', module: 'antlr'
}

sourceSets {
Expand Down Expand Up @@ -73,13 +73,14 @@ idea {
}

dependencies {
compile project(':util')
compile project(':dexlib2')
compile depends.antlr_runtime
compile depends.jcommander
compile depends.stringtemplate
implementation project(':util')
implementation project(':dexlib2')
implementation depends.antlr_runtime
implementation depends.jcommander
implementation depends.stringtemplate
implementation depends.guava

testCompile depends.junit
testImplementation depends.junit

antlr depends.antlr
}
Expand All @@ -90,7 +91,7 @@ processResources.expand('version': version)
// Build a separate jar that contains all dependencies
task fatJar(type: Jar, dependsOn: jar) {
from sourceSets.main.output
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }

classifier = 'fat'

Expand Down
10 changes: 5 additions & 5 deletions util/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
*/

dependencies {
compile project(':dexlib2')
compile depends.findbugs
compile depends.guava
compile depends.jcommander
testCompile depends.junit
implementation project(':dexlib2')
implementation depends.findbugs
implementation depends.guava
implementation depends.jcommander
testImplementation depends.junit
}

uploadArchives {
Expand Down

0 comments on commit 53b52f0

Please sign in to comment.