Skip to content

Commit

Permalink
Remove incompatible parallelization (fixes #255)
Browse files Browse the repository at this point in the history
Unfortunately the GPars trick is not safe, causing deadlocks with other
plugins. The safest solution is to remove and eventually use newer
Gradle apis that expose some parallel support. The core performance
issue, though, is that Gradle does not resolve dependencies in parallel
so doing project & configurations was a marginal gain.
  • Loading branch information
ben-manes committed Feb 27, 2019
1 parent 5b0afb0 commit fa17d54
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ out
.settings
.project
.gradle
.vscode/
.idea/
*.iml
*.ipr
Expand Down
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ apply plugin: 'nexus'
apply plugin: 'codenarc'

group = 'com.github.ben-manes'
version = '0.20.0'
version = '0.21.0'

sourceCompatibility = '1.6'

Expand Down Expand Up @@ -52,8 +52,7 @@ dependencies {
compile gradleApi()
compile localGroovy()

compile 'com.thoughtworks.xstream:xstream:1.4.10',
'org.codehaus.gpars:gpars:1.2.1'
compile 'com.thoughtworks.xstream:xstream:1.4.10'
testCompile gradleTestKit()
testCompile('org.spockframework:spock-core:1.0-groovy-2.4') {
exclude(module: 'groovy-all')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.github.benmanes.gradle.versions.updates
import com.github.benmanes.gradle.versions.updates.gradle.GradleUpdateChecker
import groovy.transform.TupleConstructor
import groovy.transform.TypeChecked
import groovyx.gpars.GParsPool
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.UnresolvedDependency
Expand Down Expand Up @@ -52,7 +51,7 @@ class DependencyUpdates {
Map<Project, Set<Configuration>> projectConfigs = project.allprojects.collectEntries { proj ->
[proj, proj.configurations.plus(proj.buildscript.configurations) as Set]
}
Set<DependencyStatus> status = resolveInParallel(projectConfigs)
Set<DependencyStatus> status = resolveProjects(projectConfigs)

VersionMapping versions = new VersionMapping(project, status)
Set<UnresolvedDependency> unresolved =
Expand All @@ -63,22 +62,14 @@ class DependencyUpdates {
return createReporter(versions, unresolved, projectUrls)
}

@TypeChecked(SKIP)
private Set<DependencyStatus> resolveInParallel(Map<Project, Set<Configuration>> projectConfigs) {
int numberOfThreads = Math.min((int) 1.5 * Runtime.getRuntime().availableProcessors(),
projectConfigs.values().collect { it.size() }.sum())
def pool = GParsPool.createPool(numberOfThreads)
return GParsPool.withExistingPool(pool) {
projectConfigs.keySet().collectParallel { proj ->
Set<Configuration> configurations = projectConfigs.get(proj)
Resolver resolver = new Resolver(proj, resolutionStrategy, pool)
GParsPool.withExistingPool(pool) {
configurations.collectParallel { Configuration config ->
resolve(resolver, proj, config)
}.flatten() as Set<DependencyStatus>
}
private Set<DependencyStatus> resolveProjects(Map<Project, Set<Configuration>> projectConfigs) {
projectConfigs.keySet().collect { proj ->
Set<Configuration> configurations = projectConfigs.get(proj)
Resolver resolver = new Resolver(proj, resolutionStrategy)
configurations.collect { Configuration config ->
resolve(resolver, proj, config)
}.flatten() as Set<DependencyStatus>
}
}.flatten() as Set<DependencyStatus>
}

private Set<DependencyStatus> resolve(Resolver resolver, Project proj, Configuration config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package com.github.benmanes.gradle.versions.updates

import groovy.transform.TypeChecked
import groovyx.gpars.GParsPool
import java.util.concurrent.ConcurrentMap
import java.util.concurrent.ConcurrentHashMap
import org.gradle.api.Project
Expand Down Expand Up @@ -51,18 +50,16 @@ import static org.gradle.api.specs.Specs.SATISFIES_ALL
*/
@TypeChecked
class Resolver {
final Object pool
final Project project
final Closure resolutionStrategy
final boolean useSelectionRules
final boolean collectProjectUrls
final ConcurrentMap<ModuleVersionIdentifier, ProjectUrl> projectUrls

Resolver(Project project, Closure resolutionStrategy, Object pool) {
Resolver(Project project, Closure resolutionStrategy) {
this.projectUrls = new ConcurrentHashMap<>()
this.resolutionStrategy = resolutionStrategy
this.project = project
this.pool = pool

useSelectionRules = new VersionComparator(project)
.compare(project.gradle.gradleVersion, '2.2') >= 0
Expand All @@ -84,22 +81,19 @@ class Resolver {
}

/** Returns the version status of the configuration's dependencies. */
@TypeChecked(SKIP)
private Set<DependencyStatus> getStatus(Map<Coordinate.Key, Coordinate> coordinates,
Set<ResolvedDependency> resolved, Set<UnresolvedDependency> unresolved) {
Set<DependencyStatus> result = Collections.synchronizedSet(new HashSet<>())

GParsPool.withExistingPool(pool) {
resolved.eachParallel { dependency ->
Coordinate resolvedCoordinate = Coordinate.from(dependency.module.id)
Coordinate originalCoordinate = coordinates.get(resolvedCoordinate.key)
Coordinate coord = originalCoordinate ?: resolvedCoordinate
if ((originalCoordinate == null) && (resolvedCoordinate.groupId != 'null')) {
project.logger.info("Skipping hidden dependency: ${resolvedCoordinate}")
} else {
String projectUrl = getProjectUrl(dependency.module.id)
result.add(new DependencyStatus(coord, resolvedCoordinate.version, projectUrl))
}
Set<DependencyStatus> result = new HashSet<>()

resolved.each { dependency ->
Coordinate resolvedCoordinate = Coordinate.from(dependency.module.id)
Coordinate originalCoordinate = coordinates.get(resolvedCoordinate.key)
Coordinate coord = originalCoordinate ?: resolvedCoordinate
if ((originalCoordinate == null) && (resolvedCoordinate.groupId != 'null')) {
project.logger.info("Skipping hidden dependency: ${resolvedCoordinate}")
} else {
String projectUrl = getProjectUrl(dependency.module.id)
result.add(new DependencyStatus(coord, resolvedCoordinate.version, projectUrl))
}
}
for (UnresolvedDependency dependency : unresolved) {
Expand Down

0 comments on commit fa17d54

Please sign in to comment.