Unnecessary (?) dependency on Android build chain
zbigniew-malinowski opened this issue · 3 comments
Hi,
I'd like to use auto-value-moshi on a pure java project. I thought it should be possible, since both autovalue and moshi are not Android dependent.
However, the plugin needs a gradle plugin, which works only with android/android-library project types:
com.neenbedankt.gradle.plugins:android-apt
Would it be possible to use another annotation processing plugin, so the tool's usage is not restricted to Android only?
I tried net.ltgt.apt, but it doesn't seem to work. The implementation for JsonAdapter.Factory is not generated, while autovalue data classes' code generation works fine.
This is my adapter factory (copied from the snippet in Readme):
@MoshiAdapterFactory
public abstract class MyAdapterFactory implements JsonAdapter.Factory {
public static JsonAdapter.Factory create() {
return new AutoValueMoshi_MyAdapterFactory();
}
}
And this is my build.gradle:
group 'com.example'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'net.ltgt.apt'
apply plugin: 'idea'
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "net.ltgt.gradle:gradle-apt-plugin:0.9"
}
}
repositories {
mavenCentral()
}
dependencies {
compileOnly "com.google.auto.value:auto-value:1.2"
apt "com.google.auto.value:auto-value:1.2"
compileOnly 'com.ryanharter.auto.value:auto-value-moshi-annotations:0.4.3'
apt 'com.ryanharter.auto.value:auto-value-moshi:0.4.3'
compile 'com.squareup.moshi:moshi:1.4.0'
}
Am I missing something?
OK, I've found the problem. I misunderstood how it was supposed to work, thinking that I won't need to add:
public static Foo jsonAdapter(Moshi moshi)
When this method is present, the code is generated properly.
Sorry for bothering!