diff --git a/README-zh.md b/README-zh.md index 17c528d73..66686cb50 100644 --- a/README-zh.md +++ b/README-zh.md @@ -9,7 +9,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.uber:okbuck:0.24.3' + classpath 'com.uber:okbuck:0.24.4' } } diff --git a/README.md b/README.md index 588501c88..f5b1fd1e9 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.uber:okbuck:0.24.3' + classpath 'com.uber:okbuck:0.24.4' } } diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 2937ffec0..7ad274adb 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -48,7 +48,7 @@ task sourcesJar(type: Jar) { classifier = 'sources' } -def publishVersion = '0.24.3' +def publishVersion = '0.24.4' group = 'com.uber' version = publishVersion def siteUrl = 'https://github.com/uber/okbuck' diff --git a/buildSrc/src/main/groovy/com/uber/okbuck/OkBuckGradlePlugin.groovy b/buildSrc/src/main/groovy/com/uber/okbuck/OkBuckGradlePlugin.groovy index c286ac348..5c7ee88d0 100644 --- a/buildSrc/src/main/groovy/com/uber/okbuck/OkBuckGradlePlugin.groovy +++ b/buildSrc/src/main/groovy/com/uber/okbuck/OkBuckGradlePlugin.groovy @@ -89,7 +89,6 @@ class OkBuckGradlePlugin implements Plugin { // Create configurations project.configurations.maybeCreate(TransformUtil.CONFIGURATION_TRANSFORM) Configuration forced = project.configurations.maybeCreate(FORCED_OKBUCK) - forced.transitive = false // Create tasks Task setupOkbuck = project.task('setupOkbuck') diff --git a/buildSrc/src/main/groovy/com/uber/okbuck/core/dependency/DependencyCache.groovy b/buildSrc/src/main/groovy/com/uber/okbuck/core/dependency/DependencyCache.groovy index 89d44eed0..28d06fd98 100644 --- a/buildSrc/src/main/groovy/com/uber/okbuck/core/dependency/DependencyCache.groovy +++ b/buildSrc/src/main/groovy/com/uber/okbuck/core/dependency/DependencyCache.groovy @@ -35,7 +35,7 @@ class DependencyCache { private final Set created = new HashSet<>() private final Set requested = ConcurrentHashMap.newKeySet() - private final Map forcedDeps = new HashMap<>() + private final Map forcedDeps = new HashMap<>() DependencyCache(Project project, File cacheDir, String forcedConfiguration = null) { this.rootProject = project.rootProject @@ -50,7 +50,7 @@ class DependencyCache { if (forcedConfiguration) { new Scope(project, Collections.singleton(forcedConfiguration)).external.each { get(it) - forcedDeps.put(it.group + ":" + it.name, it) + forcedDeps.put(it.versionless, it) } } } @@ -81,9 +81,7 @@ class DependencyCache { } String get(ExternalDependency externalDependency, boolean resolveOnly = false) { - ExternalDependency dependency = - forcedDeps.getOrDefault(externalDependency.group + ":" + externalDependency.name, externalDependency) - + ExternalDependency dependency = forcedDeps.getOrDefault(externalDependency.versionless, externalDependency) File cachedCopy = new File(cacheDir, dependency.getCacheName(!resolveOnly)) String key = FileUtil.getRelativePath(rootProject.projectDir, cachedCopy) createLink(Paths.get(key), dependency.depFile.toPath()) @@ -99,9 +97,10 @@ class DependencyCache { /** * Gets the sources jar path for a dependency if it exists. * - * @param dependency The dependency. + * @param externalDependency The dependency. */ - void getSources(ExternalDependency dependency) { + void getSources(ExternalDependency externalDependency) { + ExternalDependency dependency = forcedDeps.getOrDefault(externalDependency.versionless, externalDependency) String key = dependency.cacheName String sourcesJarPath = sources.get(key) if (sourcesJarPath == null || !Files.exists(Paths.get(sourcesJarPath))) { @@ -135,10 +134,11 @@ class DependencyCache { /** * Get the list of annotation processor classes provided by a dependency. * - * @param dependency The dependency + * @param externalDependency The dependency * @return The list of annotation processor classes available in the manifest */ - List getAnnotationProcessors(ExternalDependency dependency) { + List getAnnotationProcessors(ExternalDependency externalDependency) { + ExternalDependency dependency = forcedDeps.getOrDefault(externalDependency.versionless, externalDependency) String key = dependency.cacheName String processorsList = processors.get(key) if (processorsList == null) { @@ -166,20 +166,22 @@ class DependencyCache { /** * Get the packaged lint jar of an aar dependency if any. * - * @param dependency The depenency + * @param externalDependency The depenency * @return path to the lint jar in the cache. */ - String getLintJar(ExternalDependency dependency) { + String getLintJar(ExternalDependency externalDependency) { + ExternalDependency dependency = forcedDeps.getOrDefault(externalDependency.versionless, externalDependency) return getAarEntry(dependency, lintJars, "lint.jar", "-lint.jar") } /** * Get the packaged proguard config of an aar dependency if any. * - * @param dependency The depenency + * @param externalDependency The depenency * @return path to the proguard config in the cache. */ - File getProguardConfig(ExternalDependency dependency) { + File getProguardConfig(ExternalDependency externalDependency) { + ExternalDependency dependency = forcedDeps.getOrDefault(externalDependency.versionless, externalDependency) String entry = getAarEntry(dependency, proguardConfigs, "proguard.txt", "-proguard.pro") if (entry) { return new File(entry) diff --git a/buildSrc/src/main/java/com/uber/okbuck/core/dependency/ExternalDependency.java b/buildSrc/src/main/java/com/uber/okbuck/core/dependency/ExternalDependency.java index c5f7e0b9b..90a091f66 100644 --- a/buildSrc/src/main/java/com/uber/okbuck/core/dependency/ExternalDependency.java +++ b/buildSrc/src/main/java/com/uber/okbuck/core/dependency/ExternalDependency.java @@ -20,6 +20,7 @@ public final class ExternalDependency { public final File depFile; public final String group; public final String name; + public final VersionlessDependency versionless; public ExternalDependency(String group, String name, String version, File depFile) { this(group, name, version, depFile, false); @@ -32,20 +33,16 @@ public boolean equals(Object o) { ExternalDependency that = (ExternalDependency) o; - if (isLocal != that.isLocal) { return false; } - if (version != null ? !version.equals(that.version) : that.version != null) { return false; } - if (depFile != null ? !depFile.equals(that.depFile) : that.depFile != null) { return false; } - if (group != null ? !group.equals(that.group) : that.group != null) { return false; } - return name != null ? name.equals(that.name) : that.name == null; + if (!version.equals(that.version)) { return false; } + if (!group.equals(that.group)) { return false; } + return name.equals(that.name); } @Override public int hashCode() { - int result = (isLocal ? 1 : 0); - result = 31 * result + (version != null ? version.hashCode() : 0); - result = 31 * result + (depFile != null ? depFile.hashCode() : 0); - result = 31 * result + (group != null ? group.hashCode() : 0); - result = 31 * result + (name != null ? name.hashCode() : 0); + int result = version.hashCode(); + result = 31 * result + group.hashCode(); + result = 31 * result + name.hashCode(); return result; } @@ -86,10 +83,28 @@ private ExternalDependency(String group, String name, String version, File depFi } this.depFile = depFile; + this.versionless = new VersionlessDependency(group, name); } public static ExternalDependency fromLocal(File localDep) { String baseName = FilenameUtils.getBaseName(localDep.getName()); return new ExternalDependency(baseName, baseName, LOCAL_DEP_VERSION, localDep, true); } + + public static class VersionlessDependency { + private final String group; + private final String name; + + VersionlessDependency(String group, String name) { + this.group = group; + this.name = name; + } + + @Override + public int hashCode() { + int result = group.hashCode(); + result = 31 * result + name.hashCode(); + return result; + } + } }