This article has been translated by Gemini.
I encountered some issues during the setup of wire-gradle-plugin, so I’m making a note here.
Update 2020.11.15#
The Wire documentation has been updated. It’s recommended to refer to the content of the following PR for setup. github.com
This article describes the setup method I personally verified before this PR was released.
What is Wire?#
It’s a library for generating Kotlin or Java code from Protocol Buffers .proto files. As stated in the documentation, it’s developed for Android and Java. (It officially supported Proto3 in September 2020.)
Note: (this plugin is an old one and is now deprecated.)
What is wire-gradle-plugin?#
It’s a sub-library within the Wire library. It can be used as a Gradle plugin. github.com
There is a description saying that if you just want to use the Compiler in the Wire library to compile .proto files into Kotlin or Java code, setting it up with the Gradle Plugin is easy. Since I just wanted to generate Kotlin code from proto, I attempted setup this way.
But it didn’t work well.
It seemed to result in an error saying the Plugin ID was not found.
Plugin [id: 'com.squareup.wire', version: 'xxx'] was not found in any of the following sources:Cause#
It’s not certain, but it seems to be around here:
- Add plugin to the Gradle Plugin Repo · Issue #1828 · square/wire · GitHub
- Unable to use wire-gradle-plugin:3.5.0 using Gradle Kotlin DSL? · Issue #1848 · square/wire · GitHub
Solution#
As described in the issues above, add settings to settings.gradle / settings.gradle.kts.
// https://github.com/square/wire/issues/1029#issuecomment-540152640
pluginManagement {
resolutionStrategy {
eachPlugin {
if (requested.id.id == 'com.squareup.wire') {
useModule("com.squareup.wire:wire-gradle-plugin:${requested.version}")
}
}
}
}I was able to solve it by including the above settings. Once the root cause is resolved, these settings will likely be unnecessary.