|
| 1 | +/* |
| 2 | + * (c) Copyright 2024 Palantir Technologies Inc. All rights reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.palantir.gradle.plugintesting; |
| 18 | + |
| 19 | +import com.palantir.gradle.testing.execution.GradleInvoker; |
| 20 | +import com.palantir.gradle.testing.junit.GradlePluginTests; |
| 21 | +import com.palantir.gradle.testing.project.RootProject; |
| 22 | +import org.junit.jupiter.api.BeforeEach; |
| 23 | +import org.junit.jupiter.api.Test; |
| 24 | + |
| 25 | +@GradlePluginTests |
| 26 | +class TestDependencyVersionsTaskTest { |
| 27 | + |
| 28 | + @BeforeEach |
| 29 | + void beforeEach(RootProject rootProject) { |
| 30 | + rootProject |
| 31 | + .gradlePropertiesFile() |
| 32 | + .appendProperty(PluginTestingPlugin.PLUGIN_VERSION_PROPERTY_NAME, System.getProperty("projectVersion")); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + void write_versions_without_GCV(GradleInvoker gradleInvoker, RootProject rootProject) { |
| 37 | + rootProject.buildGradle().plugins().add("groovy"); |
| 38 | + rootProject.buildGradle().plugins().add("com.palantir.gradle-plugin-testing"); |
| 39 | + |
| 40 | + // language=gradle |
| 41 | + rootProject.buildGradle().append(""" |
| 42 | + repositories { |
| 43 | + mavenCentral() |
| 44 | + mavenLocal() |
| 45 | + } |
| 46 | +
|
| 47 | + dependencies { |
| 48 | + //WARNING: Do not include any dependencies here that the plugin-testing-core project uses in it's |
| 49 | + // api or implementation configurations. Because the plugin adds the plugin-testing-core artifact as |
| 50 | + // a testImplementation dependency, we get the transitive dependencies of it (e.g. guava). Since those |
| 51 | + // versions will update over time this test could start erroneously failing. So just list some random |
| 52 | + // dependencies here that are unlikely to be added to the plugin-test-core project. |
| 53 | + //implementation 'com.google.guava:guava:33.3.1-jre' |
| 54 | + implementation 'org.ow2.asm:asm:9.7.1' |
| 55 | +
|
| 56 | + testImplementation 'org.apache.httpcomponents.client5:httpclient5:5.3.1' |
| 57 | +
|
| 58 | + testRuntimeOnly 'com.palantir.gradle.consistentversions:gradle-consistent-versions:2.31.0' |
| 59 | + } |
| 60 | + """); |
| 61 | + |
| 62 | + gradleInvoker.withArgs("writeTestDependencyVersions").buildsSuccessfully(); |
| 63 | + |
| 64 | + rootProject |
| 65 | + .buildDir() |
| 66 | + .file("plugin-testing/dependency-versions.properties") |
| 67 | + .assertThat() |
| 68 | + .exists(); |
| 69 | + |
| 70 | + rootProject |
| 71 | + .buildDir() |
| 72 | + .file("plugin-testing/dependency-versions.properties") |
| 73 | + .assertThat() |
| 74 | + .content() |
| 75 | + .doesNotContain("null") |
| 76 | + .contains("org.ow2.asm:asm=9.7.1") |
| 77 | + .contains("org.apache.httpcomponents.client5:httpclient5=5.3.1") |
| 78 | + .contains("com.palantir.gradle.consistentversions:gradle-consistent-versions=2.31.0"); |
| 79 | + |
| 80 | + for (String name : PluginTestingPlugin.CORE_MAVEN_NAMES) { |
| 81 | + rootProject |
| 82 | + .buildDir() |
| 83 | + .file("plugin-testing/dependency-versions.properties") |
| 84 | + .assertThat() |
| 85 | + .content() |
| 86 | + .contains("com.palantir.gradle.plugintesting:" + name); |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + void write_versions_with_GCV(GradleInvoker gradleInvoker, RootProject rootProject) { |
| 92 | + // remember - the resolved version for this dependency is using the information passed from the version of the |
| 93 | + // plugin |
| 94 | + // applied to the gradle-plugin-test project itself, _not_ the current version under test. So the |
| 95 | + // addBuildScriptDependencies code and the "resolve" logic it calls is the current version, but the information |
| 96 | + // it is working with is from the last published version of the plugin (assuming that's the one applied to the |
| 97 | + // root build.gradle file of this project. |
| 98 | + rootProject |
| 99 | + .buildGradle() |
| 100 | + .append(TestContentHelpers.addBuildScriptBlock( |
| 101 | + "mavenCentral()", "com.palantir.gradle.consistentversions:gradle-consistent-versions")); |
| 102 | + |
| 103 | + rootProject.buildGradle().plugins().add("com.palantir.consistent-versions"); |
| 104 | + rootProject.buildGradle().plugins().add("groovy"); |
| 105 | + rootProject.buildGradle().plugins().add("com.palantir.gradle-plugin-testing"); |
| 106 | + |
| 107 | + // language=gradle |
| 108 | + rootProject.buildGradle().append(""" |
| 109 | + repositories { |
| 110 | + mavenCentral() |
| 111 | + mavenLocal() |
| 112 | + } |
| 113 | +
|
| 114 | + dependencies { |
| 115 | + implementation 'com.google.guava:guava' |
| 116 | +
|
| 117 | + testImplementation 'org.junit.jupiter:junit-jupiter' |
| 118 | + testImplementation 'com.netflix.nebula:nebula-test' |
| 119 | +
|
| 120 | + testRuntimeOnly 'com.palantir.gradle.consistentversions:gradle-consistent-versions' |
| 121 | + } |
| 122 | + """); |
| 123 | + |
| 124 | + rootProject |
| 125 | + .propertiesFile("versions.props") |
| 126 | + .appendProperty( |
| 127 | + "org.junit.jupiter:junit-jupiter", |
| 128 | + TestDependencyVersions.version("org.junit.jupiter:junit-jupiter")) |
| 129 | + .appendProperty( |
| 130 | + "com.netflix.nebula:nebula-test", |
| 131 | + TestDependencyVersions.version("com.netflix.nebula:nebula-test")) |
| 132 | + .appendProperty("com.google.guava:guava", TestDependencyVersions.version("com.google.guava:guava")) |
| 133 | + .appendProperty( |
| 134 | + "com.palantir.gradle.consistentversions:gradle-consistent-versions", |
| 135 | + TestDependencyVersions.version( |
| 136 | + "com.palantir.gradle.consistentversions:gradle-consistent-versions")); |
| 137 | + |
| 138 | + gradleInvoker.withArgs("writeVersionLocks").buildsSuccessfully(); |
| 139 | + |
| 140 | + gradleInvoker.withArgs("writeTestDependencyVersions").buildsSuccessfully(); |
| 141 | + |
| 142 | + rootProject |
| 143 | + .buildDir() |
| 144 | + .file("plugin-testing/dependency-versions.properties") |
| 145 | + .assertThat() |
| 146 | + .exists(); |
| 147 | + |
| 148 | + rootProject |
| 149 | + .buildDir() |
| 150 | + .file("plugin-testing/dependency-versions.properties") |
| 151 | + .assertThat() |
| 152 | + .content() |
| 153 | + .doesNotContain("null") |
| 154 | + .contains("org.junit.jupiter:junit-jupiter"); |
| 155 | + |
| 156 | + for (String name : PluginTestingPlugin.CORE_MAVEN_NAMES) { |
| 157 | + rootProject |
| 158 | + .buildDir() |
| 159 | + .file("plugin-testing/dependency-versions.properties") |
| 160 | + .assertThat() |
| 161 | + .content() |
| 162 | + .contains("com.palantir.gradle.plugintesting:" + name); |
| 163 | + } |
| 164 | + } |
| 165 | +} |
0 commit comments