Skip to content

Commit

Permalink
Gradle 4.8 Compatibilty #19
Browse files Browse the repository at this point in the history
  • Loading branch information
warnyul committed Jun 10, 2018
1 parent b5de726 commit 715aeca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.google.common.collect.Sets
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.ConfigurationContainer
import org.gradle.api.artifacts.DependencyConstraint
import org.gradle.api.artifacts.ExcludeRule
import org.gradle.api.artifacts.ModuleDependency
import org.gradle.api.artifacts.PublishArtifact
import org.gradle.api.attributes.AttributeContainer
Expand Down Expand Up @@ -68,6 +69,7 @@ final class AndroidVariantLibrary implements SoftwareComponentInternal {
private def dependencies
private def dependencyConstraints
private def capabilities
private def excludeRules

CompileUsage(ConfigurationContainer configurations, ImmutableAttributesFactory attributesFactory, PublishConfiguration publishConfiguration, Usage usage) {
super(configurations, attributesFactory, publishConfiguration, usage)
Expand All @@ -91,16 +93,8 @@ final class AndroidVariantLibrary implements SoftwareComponentInternal {
Set<? extends DependencyConstraint> getDependencyConstraints() {
if (dependencyConstraints == null) {
def apiElements = publishConfiguration.publishConfig + JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME.capitalize()

def incoming = configurations.getByName(apiElements).getIncoming()

if (incoming.metaClass.respondsTo(incoming, 'getDependencyConstraints')) {
// Gradle 4.6
dependencyConstraints = incoming.getDependencyConstraints()
} else {
// Gradle 4.5
dependencyConstraints = incoming.getDependencies().withType(DependencyConstraint)
}
dependencyConstraints = incoming.getDependencyConstraints()
}
return dependencyConstraints
}
Expand All @@ -115,13 +109,23 @@ final class AndroidVariantLibrary implements SoftwareComponentInternal {
}
return capabilities
}

@Override
Set<ExcludeRule> getGlobalExcludes() {
if (excludeRules == null) {
def apiElements = publishConfiguration.publishConfig + JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME.capitalize()
excludeRules = ImmutableSet.copyOf(configurations.getByName(apiElements).getExcludeRules())
}
return excludeRules
}
}

private static class RuntimeUsage extends BaseUsage {

private def dependencies
private def dependencyConstraints
private def capabilities
private def excludeRules

RuntimeUsage(ConfigurationContainer configurations, ImmutableAttributesFactory attributesFactory, PublishConfiguration publishConfiguration, Usage usage) {
super(configurations, attributesFactory, publishConfiguration, usage)
Expand All @@ -146,14 +150,7 @@ final class AndroidVariantLibrary implements SoftwareComponentInternal {
if (dependencyConstraints == null) {
def runtimeElements = publishConfiguration.publishConfig + JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME.capitalize()
def incoming = configurations.getByName(runtimeElements).getIncoming()

if (incoming.metaClass.respondsTo(incoming, 'getDependencyConstraints')) {
// Gradle 4.6+
dependencyConstraints = incoming.getDependencyConstraints()
} else {
// Gradle 4.5
dependencyConstraints = incoming.getDependencies().withType(DependencyConstraint)
}
dependencyConstraints = incoming.getDependencyConstraints()
}
return dependencyConstraints
}
Expand All @@ -168,6 +165,15 @@ final class AndroidVariantLibrary implements SoftwareComponentInternal {
}
return capabilities
}

@Override
Set<ExcludeRule> getGlobalExcludes() {
if (excludeRules == null) {
def runtimeElements = publishConfiguration.publishConfig + JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME.capitalize()
excludeRules = ImmutableSet.copyOf(configurations.getByName(runtimeElements).getExcludeRules())
}
return excludeRules
}
}

private static abstract class BaseUsage implements UsageContext {
Expand Down

0 comments on commit 715aeca

Please sign in to comment.