Created
June 24, 2018 10:59
-
-
Save zskamljic/15e264ce467fbc430a74dfa6b255ce17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.equaleyes.demoplugin; | |
import org.gradle.api.*; | |
@NonNullApi | |
public class DemoPlugin implements Plugin<Project> { | |
private static final String TRANSFORM_CLASS = "com.android.build.api.transform.Transform"; | |
private static final String ERROR_PLUGIN_REQUIRED = "'com.android.application' or 'com.android.library' plugin required"; | |
private static final String ERROR_PLUGIN_OUTDATED = "Gradle plugin 1.5.0 or later is required."; | |
Project project; | |
@Override | |
public void apply(Project project) { | |
this.project = project; | |
requireAndroidPlugins(); | |
requireTransformAvailable(); | |
} | |
void requireAndroidPlugins() { | |
boolean missingAndroid = project.getPlugins().withType(AppPlugin.class).isEmpty(); | |
boolean missingLibrary = project.getPlugins().withType(LibraryPlugin.class).isEmpty(); | |
if (missingAndroid && missingLibrary) { | |
throw new GradleException(ERROR_PLUGIN_REQUIRED); | |
} | |
} | |
void requireTransformAvailable() { | |
try { | |
Class.forName(TRANSFORM_CLASS); | |
} catch (ClassNotFoundException e) { | |
throw new GradleException(ERROR_PLUGIN_OUTDATED); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment