|
| 1 | +/* |
| 2 | + * (c) Copyright 2019 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 | +package com.palantir.javaformat.gradle; |
| 17 | + |
| 18 | +import com.palantir.gradle.testing.execution.GradleInvoker; |
| 19 | +import com.palantir.gradle.testing.junit.DisabledConfigurationCache; |
| 20 | +import com.palantir.gradle.testing.junit.GradlePluginTests; |
| 21 | +import com.palantir.gradle.testing.project.RootProject; |
| 22 | +import java.io.File; |
| 23 | +import org.junit.jupiter.api.Test; |
| 24 | + |
| 25 | +/** |
| 26 | + * When we were getting gradle-baseline to support the configuration cache, spotless had some poorly written tasks |
| 27 | + * which caused issues with the configuration cache. |
| 28 | + * <p> |
| 29 | + * Bumping spotless to 6.22.0 or newer fixed this, but revealed a new error — the {@code palantirJavaFormat} configuration was |
| 30 | + * being <a href="https://github.com/palantir/palantir-java-format/blob/b7b5995df3be690780939c0d0cb2ec49b99c68c8/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/spotless/NativePalantirJavaFormatStep.java#L45"> resolved eagerly</a>. |
| 31 | + * <p> |
| 32 | + * gradle-consistent-versions enforces against resolving configurations at configuration time, and throws an error. |
| 33 | + * <p> |
| 34 | + * This test forces creation of the spotless steps, which will reveal any eager resolution of configurations. |
| 35 | + */ |
| 36 | +@GradlePluginTests |
| 37 | +@DisabledConfigurationCache |
| 38 | +class SupportsCurrentSpotlessTest { |
| 39 | + private static final String CLASSPATH_FILE = new File("build/impl.classpath").getAbsolutePath(); |
| 40 | + |
| 41 | + @Test |
| 42 | + void palantirjavaformatplugin_works_with_current_spotless(GradleInvoker gradle, RootProject rootProject) { |
| 43 | + rootProject |
| 44 | + .buildGradle() |
| 45 | + .plugins() |
| 46 | + .add("java") |
| 47 | + .add("com.palantir.java-format") |
| 48 | + .add("com.palantir.consistent-versions") |
| 49 | + .add("com.diffplug.spotless"); |
| 50 | + |
| 51 | + rootProject.file("versions.props").createEmpty(); |
| 52 | + rootProject.file("versions.lock").createEmpty(); |
| 53 | + |
| 54 | + gradle.withArgs("wrapper").buildsSuccessfully(); |
| 55 | + |
| 56 | + rootProject.buildGradle().append(""" |
| 57 | + dependencies { |
| 58 | + palantirJavaFormat files(file("%s").text.split(':')) |
| 59 | + } |
| 60 | +
|
| 61 | + // This forces the realization of the spotlessJava task, creating the spotless steps. |
| 62 | + // If any configurations are eagerly resolved in the spotless steps, |
| 63 | + // consistent-versions should catch it and throw here. |
| 64 | + project.getTasks().getByName("spotlessJava") |
| 65 | + """, CLASSPATH_FILE); |
| 66 | + |
| 67 | + gradle.withArgs("classes", "--info").buildsSuccessfully(); |
| 68 | + } |
| 69 | +} |
0 commit comments