All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.gradle.vcs.internal.SourceDependencyIdentityIntegrationTest.groovy Maven / Gradle / Ivy

There is a newer version: 8.11.1
Show newest version
/*
 * Copyright 2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gradle.vcs.internal

import org.gradle.integtests.fixtures.AbstractIntegrationSpec
import org.gradle.vcs.fixtures.GitFileRepository
import org.junit.Rule
import spock.lang.Unroll


class SourceDependencyIdentityIntegrationTest extends AbstractIntegrationSpec {
    @Rule
    GitFileRepository repo = new GitFileRepository('buildB', temporaryFolder.getTestDirectory())

    def setup() {
        settingsFile << """
            rootProject.name = 'buildA'
        """
        buildFile << """
            apply plugin: 'java'
        """

        repo.file("build.gradle") << """
            apply plugin: 'java'
            group = 'org.test'
            version = '1.2'
        """
    }

    def dependency(String moduleName) {
        settingsFile << """
            sourceControl {
                vcsMappings {
                    withModule("org.test:${moduleName}") {
                        from(GitVersionControlSpec) {
                            url = uri("${repo.url}")
                        }
                    }
                }
            }
        """
        buildFile << """
            dependencies { implementation 'org.test:${moduleName}:1.2' }
        """
    }

    @Unroll
    def "includes build identifier in error message on failure to resolve dependencies of build with #display"() {
        repo.file("settings.gradle") << """
            ${settings}
        """
        repo.file("build.gradle") << """
            dependencies { implementation "test:test:1.2" }
        """
        repo.commit("initial version")
        repo.createLightWeightTag("1.2")
        dependency(buildName)

        when:
        fails(":assemble")

        then:
        failure.assertHasDescription("Could not determine the dependencies of task ':${buildName}:compileJava'.")
        failure.assertHasCause("Could not resolve all task dependencies for configuration ':${buildName}:compileClasspath'.")
        failure.assertHasCause("""Cannot resolve external dependency test:test:1.2 because no repositories are defined.
Required by:
    project :${buildName}""")

        where:
        settings                     | buildName | display
        ""                           | "buildB"  | "default root project name"
        "rootProject.name='someLib'" | "someLib" | "configured root project name"
    }

    @Unroll
    def "includes build identifier in task failure error message with #display"() {
        repo.file("settings.gradle") << """
            ${settings}
        """
        repo.file("build.gradle") << """
            classes.doLast {
                throw new RuntimeException("broken")
            }
        """
        repo.commit("initial version")
        repo.createLightWeightTag("1.2")
        dependency(buildName)

        when:
        fails(":assemble")

        then:
        failure.assertHasDescription("Execution failed for task ':${buildName}:classes'.")
        failure.assertHasCause("broken")

        where:
        settings                     | buildName | display
        ""                           | "buildB"  | "default root project name"
        "rootProject.name='someLib'" | "someLib" | "configured root project name"
    }

    @Unroll
    def "includes build identifier in dependency resolution results with #display"() {
        repo.file("settings.gradle") << """
            ${settings}
            include 'a'
        """
        repo.file("build.gradle") << """
            allprojects { apply plugin: 'java' }
            dependencies { implementation project(':a') }
        """
        repo.commit("initial version")
        repo.createLightWeightTag("1.2")
        dependency(buildName)

        buildFile << """
            classes.doLast {
                def components = configurations.runtimeClasspath.incoming.resolutionResult.allComponents.id
                assert components.size() == 3
                assert components[0].build.name == ':'
                assert components[0].build.currentBuild
                assert components[0].projectPath == ':'
                assert components[0].projectName == 'buildA'
                assert components[1].build.name == '${buildName}'
                assert !components[1].build.currentBuild
                assert components[1].projectPath == ':'
                assert components[1].projectName == '${buildName}'
                assert components[2].build.name == '${buildName}'
                assert !components[2].build.currentBuild
                assert components[2].projectPath == ':a'
                assert components[2].projectName == 'a'

                def selectors = configurations.runtimeClasspath.incoming.resolutionResult.allDependencies.requested
                assert selectors.size() == 2
                assert selectors[0].displayName == 'org.test:${buildName}:1.2'
                assert selectors[1].displayName == 'project :${buildName}:a'
                // TODO - should be buildB
                assert selectors[1].buildName == 'buildB'
                assert selectors[1].projectPath == ':a'
            }
        """

        expect:
        succeeds( ":assemble")

        where:
        settings                     | buildName | display
        ""                           | "buildB"  | "default root project name"
        "rootProject.name='someLib'" | "someLib" | "configured root project name"
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy