Skip to content

Commit

Permalink
Search for gradle build plugin in root build.gradle first
Browse files Browse the repository at this point in the history
  • Loading branch information
kezong committed Sep 3, 2020
1 parent 93d736f commit 377246c
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions source/src/main/groovy/com/kezong/fataar/VariantProcessor.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,33 @@ class VariantProcessor {
VariantProcessor(Project project, LibraryVariant variant) {
mProject = project
mVariant = variant
// gradle version
def classpathBuildscriptConfiguration = mProject.rootProject.buildscript.getConfigurations().getByName("classpath")

def artifacts = classpathBuildscriptConfiguration.getResolvedConfiguration().getResolvedArtifacts()
artifacts.find {
def artifactId = it.getModuleVersion().getId()
if (artifactId.getGroup() == "com.android.tools.build" && artifactId.getName() == "gradle") {
mGradlePluginVersion = artifactId.getVersion()
return true
checkGradlePluginVersion()
mVersionAdapter = new VersionAdapter(project, variant, mGradlePluginVersion)
}

private void checkGradlePluginVersion() {
mProject.rootProject.buildscript.getConfigurations().getByName("classpath").getDependencies().each { Dependency dep ->
if (dep.group == "com.android.tools.build" && dep.name == "gradle") {
mGradlePluginVersion = dep.version
}
}

if (mGradlePluginVersion == null) {
def classpathBuildscriptConfiguration = mProject.rootProject.buildscript.getConfigurations().getByName("classpath")
def artifacts = classpathBuildscriptConfiguration.getResolvedConfiguration().getResolvedArtifacts()
artifacts.find {
def artifactId = it.getModuleVersion().getId()
if (artifactId.getGroup() == "com.android.tools.build" && artifactId.getName() == "gradle") {
mGradlePluginVersion = artifactId.getVersion()
return true
}
return false
}
return false
}

if (mGradlePluginVersion == null) {
throw new IllegalStateException("com.android.tools.build:gradle not found in buildscript classpath")
}
mVersionAdapter = new VersionAdapter(project, variant, mGradlePluginVersion)
}

void addArtifacts(Set<ResolvedArtifact> resolvedArtifacts) {
Expand Down

0 comments on commit 377246c

Please sign in to comment.