Skip to content

Commit

Permalink
Allows for configuring RepositoryMode in settings in a declarative ma…
Browse files Browse the repository at this point in the history
…nner
  • Loading branch information
tresat committed May 6, 2024
1 parent 5f0d178 commit 743c4fd
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,30 @@ class SoftwareTypeDeclarationIntegrationTest extends AbstractIntegrationSpec imp
failure.assertHasCause("Class SoftwareTypeImplPlugin.AnotherSoftwareTypeExtension is private.")
}

def 'can configure RepositoriesMode in settings'() {
given:
file("settings.gradle.dcl") << """
dependencyResolutionManagement {
repositoriesMode = failOnProjectRepos()
repositories {
google()
}
}
rootProject.name = "example"
"""

file("build.gradle.kts") << """
repositories {
mavenCentral()
}
"""

expect:
fails(":build").with {
assertHasErrorOutput("Build was configured to prefer settings repositories over project repositories but repository 'MavenRepo' was added by build file 'build.gradle.kts'")
}
}

static String getPluginsFromIncludedBuild() {
return """
pluginManagement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,48 @@ public interface DependencyResolutionManagement {
RepositoryHandler getRepositories();

@Incubating
@Restricted
Property<RepositoriesMode> getRepositoriesMode();

/**
* Returns the {@link RepositoriesMode#PREFER_PROJECT} repositories mode type to be used in Declarative
* Gradle files.
*
* @return {@link RepositoriesMode#PREFER_PROJECT}
* @since 8.9
*/
@Incubating
@Restricted
default RepositoriesMode preferProject() {
return RepositoriesMode.PREFER_PROJECT;
}

/**
* Returns the {@link RepositoriesMode#PREFER_SETTINGS} repositories mode type to be used in Declarative
* Gradle files.
*
* @return {@link RepositoriesMode#PREFER_SETTINGS}
* @since 8.9
*/
@Incubating
@Restricted
default RepositoriesMode preferSettings() {
return RepositoriesMode.PREFER_SETTINGS;
}

/**
* Returns the {@link RepositoriesMode#FAIL_ON_PROJECT_REPOS} repositories mode type to be used in Declarative
* Gradle files.
*
* @return {@link RepositoriesMode#FAIL_ON_PROJECT_REPOS}
* @since 8.9
*/
@Incubating
@Restricted
default RepositoriesMode failOnProjectRepos() {
return RepositoriesMode.FAIL_ON_PROJECT_REPOS;
}

/**
* Registers component metadata rules used by all projects
* @param registration the registration action
Expand Down

0 comments on commit 743c4fd

Please sign in to comment.