Skip to content

Commit

Permalink
Merge pull request #15863 from gradle/ljacomet/dependency-management/…
Browse files Browse the repository at this point in the history
…central-repo-support
  • Loading branch information
big-guy committed Jan 20, 2021
2 parents 900529f + 81a51a9 commit a9dc73a
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 10 deletions.
Expand Up @@ -65,7 +65,6 @@ public SettingsInternal process(GradleInternal gradle,

gradle.getBuildListenerBroadcaster().beforeSettings(settings);
applySettingsScript(settingsScript, settings);
settings.preventFromFurtherMutation();
LOGGER.debug("Timing: Processing settings took: {}", settingsProcessingClock.getElapsed());
return settings;
}
Expand Down
Expand Up @@ -33,6 +33,7 @@ public SettingsEvaluatedCallbackFiringSettingsProcessor(SettingsProcessor delega
public SettingsInternal process(GradleInternal gradle, SettingsLocation settingsLocation, ClassLoaderScope buildRootClassLoaderScope, StartParameter startParameter) {
SettingsInternal settings = delegate.process(gradle, settingsLocation, buildRootClassLoaderScope, startParameter);
gradle.getBuildListenerBroadcaster().settingsEvaluated(settings);
settings.preventFromFurtherMutation();
return settings;
}
}
Expand Up @@ -762,6 +762,41 @@ You can figure out how project repositories are declared by configuring your bui
See https://docs.gradle.org/${GradleVersion.current().version}/userguide/declaring_repositories.html#sub:fail_build_on_project_repositories for details."""))
}

@Issue("https://github.com/gradle/gradle/issues/15772")
def "can add settings repositories in an init script"() {
given:
repository {
'org:module:1.0'()
}

buildFile << """
dependencies {
conf 'org:module:1.0'
}
"""

file("init.gradle") << """
settingsEvaluated {
it.dependencyResolutionManagement {
repositories {
maven { url '/doesnt/matter'}
}
}
}
"""

when:
repositoryInteractions {
'org:module:1.0' {
expectResolve()
}
}
executer.usingInitScript(file("init.gradle"))

then:
succeeds ':checkDeps'
}

void withSettingsPlugin() {
file("settings-plugin/build.gradle") << """
plugins {
Expand Down
Expand Up @@ -35,4 +35,34 @@ class GroovyProjectIntegrationTest extends AbstractIntegrationSpec {
then:
file("build/libs/javaOnly.jar").exists()
}

def "supports central repository declaration"() {
given:
buildFile << """
plugins {
id 'groovy'
}
dependencies {
implementation 'org.codehaus.groovy:groovy-all:2.5.13'
}
"""
settingsFile << """
rootProject.name = 'groovyCompilation'
dependencyResolutionManagement {
repositories {
${jcenterRepository()}
}
}
"""
and:
file('src/main/groovy/Test.groovy') << """
class Test { }
"""
when:
succeeds 'compileGroovy'

then:
executedAndNotSkipped(':compileGroovy')
}
}
Expand Up @@ -94,10 +94,6 @@ public FileCollection createDelegate() {
return project.getLayout().files(groovyJar.getFile());
}

if (project.getRepositories().isEmpty()) {
throw new GradleException("Cannot infer Groovy class path because no repository is declared for the project.");
}

String notation = groovyJar.getDependencyNotation();
List<Dependency> dependencies = Lists.newArrayList();
// project.getDependencies().create(String) seems to be the only feasible way to create a Dependency with a classifier
Expand Down
Expand Up @@ -37,4 +37,33 @@ class ScalaProjectIntegrationTest extends AbstractIntegrationSpec {
succeeds "build"
file("build/libs/javaOnly.jar").assertExists()
}

def "supports central repository declaration"() {
given:
buildFile << """
plugins {
id 'scala'
}
dependencies {
implementation 'org.scala-lang:scala-library:2.11.12'
}
"""
settingsFile << """
rootProject.name = 'scalaCompilation'
dependencyResolutionManagement {
repositories {
${jcenterRepository()}
}
}
"""
and:
file('src/main/scala/Test.scala') << """
class Test { }
"""
when:
succeeds 'compileScala'

then:
executedAndNotSkipped(':compileScala')
}
}
Expand Up @@ -84,10 +84,6 @@ public String getDisplayName() {

@Override
public FileCollection createDelegate() {
if (project.getRepositories().isEmpty()) {
throw new GradleException(String.format("Cannot infer Scala class path because no repository is declared in %s", project));
}

File scalaLibraryJar = findScalaJar(classpath, "library");
if (scalaLibraryJar == null) {
throw new GradleException(String.format("Cannot infer Scala class path because no Scala library Jar was found. "
Expand Down
Expand Up @@ -84,7 +84,8 @@ class ScalaRuntimeTest extends AbstractProjectBuilderSpec {

then:
GradleException e = thrown()
e.message == "Cannot infer Scala class path because no repository is declared in $project"
e.message == "Could not resolve all files for configuration ':detachedConfiguration1'."
e.cause.message.startsWith("Cannot resolve external dependency org.scala-lang:scala-compiler:2.10.1 because no repositories are defined.")
}

def "inference fails if 'scalaTools' configuration is empty and no Scala library Jar is found on class path"() {
Expand Down

0 comments on commit a9dc73a

Please sign in to comment.