Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes regressions reported in 4.10.1 #6754

Merged
merged 2 commits into from Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -16,7 +16,6 @@
package org.gradle.scala

import org.gradle.integtests.fixtures.AbstractIntegrationSpec
import spock.lang.Ignore
import spock.lang.Issue

class ScalaPluginIntegrationTest extends AbstractIntegrationSpec {
Expand Down Expand Up @@ -72,7 +71,6 @@ task someTask
succeeds(":a:classes", "--parallel")
}

@Ignore
@Issue("https://github.com/gradle/gradle/issues/6735")
def "can depend on the source set of another Java project"() {
settingsFile << """
Expand Down Expand Up @@ -107,7 +105,6 @@ task someTask
succeeds(":scala:testClasses")
}

@Ignore
@Issue("https://github.com/gradle/gradle/issues/6750")
def "can depend on Scala project from other project"() {
settingsFile << """
Expand Down Expand Up @@ -136,6 +133,7 @@ task someTask
}
project(":scala") {
apply plugin: 'scala'

dependencies {
compile("org.scala-lang:scala-library:2.12.6")
}
Expand Down
Expand Up @@ -16,14 +16,21 @@
package org.gradle.api.plugins.scala;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet;
import org.codehaus.groovy.runtime.InvokerHelper;
import org.gradle.api.Action;
import org.gradle.api.ActionConfiguration;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.ArtifactView;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.DependencySet;
import org.gradle.api.artifacts.component.ComponentIdentifier;
import org.gradle.api.artifacts.component.ProjectComponentIdentifier;
import org.gradle.api.attributes.AttributeDisambiguationRule;
import org.gradle.api.attributes.AttributeMatchingStrategy;
import org.gradle.api.attributes.MultipleCandidatesDetails;
import org.gradle.api.attributes.Usage;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.FileTreeElement;
Expand Down Expand Up @@ -84,7 +91,7 @@ public void apply(final Project project) {
configureScaladoc(project, scalaRuntime);
}

private void configureConfigurations(final Project project, Usage incrementalAnalysisUsage) {
private void configureConfigurations(final Project project, final Usage incrementalAnalysisUsage) {
project.getConfigurations().create(ZINC_CONFIGURATION_NAME).setVisible(false).setDescription("The Zinc incremental compiler to be used for this Scala project.")
.defaultDependencies(new Action<DependencySet>() {
@Override
Expand All @@ -99,6 +106,16 @@ public void execute(DependencySet dependencies) {
incrementalAnalysisElements.setCanBeResolved(false);
incrementalAnalysisElements.setCanBeConsumed(true);
incrementalAnalysisElements.getAttributes().attribute(Usage.USAGE_ATTRIBUTE, incrementalAnalysisUsage);

AttributeMatchingStrategy<Usage> matchingStrategy = project.getDependencies().getAttributesSchema().attribute(Usage.USAGE_ATTRIBUTE);
matchingStrategy.getDisambiguationRules().add(UsageDisambiguationRules.class, new Action<ActionConfiguration>() {
@Override
public void execute(ActionConfiguration actionConfiguration) {
actionConfiguration.params(incrementalAnalysisUsage);
actionConfiguration.params(objectFactory.named(Usage.class, Usage.JAVA_API));
actionConfiguration.params(objectFactory.named(Usage.class, Usage.JAVA_RUNTIME_JARS));
}
});
}

private static void configureSourceSetDefaults(final Project project, final Usage incrementalAnalysisUsage, final SourceDirectorySetFactory sourceDirectorySetFactory) {
Expand Down Expand Up @@ -170,6 +187,12 @@ public File call() throws Exception {
@Override
public void execute(ArtifactView.ViewConfiguration viewConfiguration) {
viewConfiguration.lenient(true);
viewConfiguration.componentFilter(new Spec<ComponentIdentifier>() {
@Override
public boolean isSatisfiedBy(ComponentIdentifier element) {
return element instanceof ProjectComponentIdentifier;
}
});
}
}).getFiles());
}
Expand Down Expand Up @@ -229,4 +252,24 @@ public FileCollection call() throws Exception {
}
});
}

static class UsageDisambiguationRules implements AttributeDisambiguationRule<Usage> {
private final ImmutableSet<Usage> expectedUsages;
private final Usage javaRuntimeJars;

@Inject
UsageDisambiguationRules(Usage incrementalAnalysis, Usage javaApi, Usage javaRuntimeJars) {
this.javaRuntimeJars = javaRuntimeJars;
this.expectedUsages = ImmutableSet.of(incrementalAnalysis, javaApi, javaRuntimeJars);
}

@Override
public void execute(MultipleCandidatesDetails<Usage> details) {
if (details.getConsumerValue() == null) {
if (details.getCandidateValues().equals(expectedUsages)) {
details.closestMatch(javaRuntimeJars);
}
}
}
}
}