I'm unfortunately working on a project where i hav...
# community-support
c
I'm unfortunately working on a project where i have to migrate some legacy definition blocks to the modern way this is what ive got left
Copy code
buildscript {
   // this is all I have left to migrate
    ext.kotlin_version = '1.9.24'
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
        classpath 'com.android.tools.build:gradle:8.10.1'
        classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3'
        classpath "org.jacoco:org.jacoco.core:0.8.13"
    }
}
it seems like theres no way to just migrate to new plugins block directly... instead you have to lookup the documentation for each plugin. am i correct in my understanding? and what do i do if a plugin doesn't publish how to use the new plugins block (like butterknife)?
e
if there is no published marker, then
Copy code
// settings.gradle.kts
pluginManagement {
    resolutionStrategy {
        eachPlugin {
            if (requested.id == "com.jakewharton.butterknife") useModule("com.jakewharton:butterknife-gradle-plugin")
        }
    }
}
enables
Copy code
plugins {
    id("com.jakewharton.butterknife")
}
to work without additional buildscript setup. but as https://github.com/JakeWharton/butterknife says, > Attention: This tool is now deprecated. Please switch to view binding.
other than that,
Copy code
// root build.gradle.kts
plugins {
    val kotlinVersion = "1.9.24"
    id("com.android.library") version "8.10.1" apply false
    id("org.jetbrains.kotlin.android") version kotlinVersion apply false
    id("org.jetbrains.kotlin.plugin.serialization") version kotlinVersion apply false
}
puts them in the root build script's classpath which means all subprojects will be able to
Copy code
plugins {
    id("com.android.library")
    id("org.jetbrains.kotlin.jvm")
    id("org.jetbrains.kotlin.plugin.serialization")
}
without a version specifier. I'd switch to the version catalog though
you also should not need jacoco in the buildscript classpath, you can simply set the version with
Copy code
plugins {
    id("jacoco")
}
jacoco {
    toolVersion = "0.8.13"
}
in JVM projects or
Copy code
android {
    testCoverage {
        jacocoVersion = "0.8.13"
    }
}
in Android projects
c
thanks. so if i understand correctly to use the "new" plugins block, plugins had to go out of their way to publish a "marker"? and if they dont, then i gotta do what you said above?
and yeah. i will move away from butterknife, but for now its my task to migrate to new settings.gradle and plugins block. so im trying to just do a 1 for 1 swap there and keep it as close as possible to what we have. and then hopefully migrate soon after
and yeah. version catalogs are on the horizon I guess there's no 1 for replacement of
classpath 'com.android.tools.build:gradle:8.10.1'
? i need to either use android library or android application?
e
IMO you have to go out of your way to not publish the plugin marker… it's been automated since https://docs.gradle.org/2.14/userguide/plugins.html#sec:plugin_markers
if you use both in subprojects, you can list both in your root build gradle
1
(or you could list just one, and since they are implemented in the same artifact, it'll work, but you're relying on that)
c
> IMO you have to go out of your way to not publish the plugin marker… it's been automated since cool. i didn't know it was technically an additional step (at least... in the past). that makes sense why it doesn't just work with some of these deps (like butterknife, and some other lesser known ones i excluded here) to just use the group + artifact id
i cannot wait to have this done. thanks ephemient
For anyone else following along I had to add a version number to the end of if (requested.id == "com.jakewharton.butterknife") useModule("com.jakewhartonbutterknife gradle pluginVERSION") or else it wouldn't resolve. Also, i can't seem to define a variable in the plugins {} block which is sort of annoying (at least for now before I move to toml)
e
use
requested.version
c
just following up do you mean it should be
if (requested.version == "com.jakewharton.butterknife") useModule("com.jakewharton:butterknife-gradle-plugin:10.2.3")
?
oh. you mean as version string interpolation!?
e
Copy code
if (requested.id == "com.jakewharton.butterknife") useModule("com.jakewharton:butterknife-gradle-plugin:${requested.version}")
c
cool. i had to do add an extra toString or else I get "== between objects of invocertible types "PluginId" and "String"" but I think im solid now. woot
if (requested.id.toString() == "com.jakewharton.butterknife") useModule("com.jakewharton:butterknife-gradle-plugin:${requested.version}")e
e
oh right, I think it might be
.id.id
or something
☝️ 1
c
oh. id.id exists. lemme try that