android - How to develop Custom Gradle Plugin with Java -
i attempting develop custom gradle plugin using java (and not groovy).
i using groovy plugin guide
@override void apply(project project) { def hasapp = project.plugins.withtype(appplugin) def haslib = project.plugins.withtype(libraryplugin) if (!hasapp && !haslib) { throw new illegalstateexception("'android' or 'android-library' plugin required.") } final def log = project.logger final def variants if (hasapp) { variants = project.android.applicationvariants } else { variants = project.android.libraryvariants } project.dependencies { debugcompile 'com.jakewharton.hugo:hugo-runtime:1.2.2-snapshot' // todo should come transitively debugcompile 'org.aspectj:aspectjrt:1.8.6' compile 'com.jakewharton.hugo:hugo-annotations:1.2.2-snapshot' } project.extensions.create('hugo', hugoextension) variants.all { variant -> if (!variant.buildtype.isdebuggable()) { log.debug("skipping non-debuggable build type '${variant.buildtype.name}'.") return; } else if (!project.hugo.enabled) { log.debug("hugo not disabled.") return; } javacompile javacompile = variant.javacompile javacompile.dolast { string[] args = [ "-showweaveinfo", "-1.5", "-inpath", javacompile.destinationdir.tostring(), "-aspectpath", javacompile.classpath.aspath, "-d", javacompile.destinationdir.tostring(), "-classpath", javacompile.classpath.aspath, "-bootclasspath", project.android.bootclasspath.join(file.pathseparator) ] log.debug "ajc args: " + arrays.tostring(args) messagehandler handler = new messagehandler(true); new main().run(args, handler); (imessage message : handler.getmessages(null, true)) { switch (message.getkind()) { case imessage.abort: case imessage.error: case imessage.fail: log.error message.message, message.thrown break; case imessage.warning: log.warn message.message, message.thrown break; case imessage.info: log.info message.message, message.thrown break; case imessage.debug: log.debug message.message, message.thrown break; } } } } } } i have developed checking android app / android library
final plugincollection hasandroidappplugin = project.getplugins().withtype(appplugin.class); final plugincollection hasandroidlibraryplugin = project.getplugins().withtype(libraryplugin.class); if (hasandroidappplugin.isempty() & hasandroidlibraryplugin.isempty()) { throw new illegalstateexception("'android' or 'android-library' plugin required."); } and setting dependencies
final dependencyhandler dependencyhandler = project.getdependencies(); dependencyhandler.add("debugcompile", "com.example.perspective:perspective-runtime:0.0.1"); dependencyhandler.add("debugcompile", "org.aspectj:aspectjrt:1.8.10.3"); how can achieve following using java?
i stuck trying identify "variants" e.g. applicationvariants/libraryvariants.
if (hasapp) { variants = project.android.applicationvariants } else { variants = project.android.libraryvariants }
disclaimer: i'm familiar gradle, not android
i'm guessing android property extension object. see plugin docs , extensioncontainer
if put println android build
println "${project.android.class.name}" you'll see type extension object is. can do
androidmodel amodel = getproject().getextensions().getbytype(androidmodel.class) i'm using androidmodel here, you'll replace whatever printed in println above
you do
object amodel = getproject().getextensions().getbyname("android"); system.out.println(amodel.getclass().getname());
Comments
Post a Comment