diff --git a/.gitignore b/.gitignore index ee2b304d..3b5e3789 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build +!/**/src/**/build .gradle .idea/ out diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 00000000..e91e108c --- /dev/null +++ b/buildSrc/build.gradle @@ -0,0 +1,38 @@ +plugins { + id "java-gradle-plugin" + id "io.spring.javaformat" version "${javaFormatVersion}" + id "checkstyle" +} + +repositories { + mavenCentral() + gradlePluginPortal() + maven { url "https://repo.spring.io/release" } +} + +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + +dependencies { + checkstyle "io.spring.javaformat:spring-javaformat-checkstyle:${javaFormatVersion}" + implementation("io.spring.javaformat:spring-javaformat-gradle-plugin:${javaFormatVersion}") +} + +checkstyle { + def archive = configurations.checkstyle.filter { it.name.startsWith("spring-javaformat-checkstyle")} + config = resources.text.fromArchiveEntry(archive, "io/spring/javaformat/checkstyle/checkstyle.xml") + toolVersion = 8.11 +} + +gradlePlugin { + plugins { + conventionsPlugin { + id = "org.springframework.graphql.conventions" + implementationClass = "org.springframework.graphql.build.ConventionsPlugin" + } + } +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/buildSrc/gradle.properties b/buildSrc/gradle.properties new file mode 100644 index 00000000..9a7bd463 --- /dev/null +++ b/buildSrc/gradle.properties @@ -0,0 +1 @@ +javaFormatVersion=0.0.28 \ No newline at end of file diff --git a/buildSrc/settings.gradle b/buildSrc/settings.gradle new file mode 100644 index 00000000..3cf4a712 --- /dev/null +++ b/buildSrc/settings.gradle @@ -0,0 +1,13 @@ +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal() + } + resolutionStrategy { + eachPlugin { + if (requested.id.id == "io.spring.javaformat") { + useModule "io.spring.javaformat:spring-javaformat-gradle-plugin:${requested.version}" + } + } + } +} \ No newline at end of file diff --git a/buildSrc/src/main/java/org/springframework/graphql/build/ConventionsPlugin.java b/buildSrc/src/main/java/org/springframework/graphql/build/ConventionsPlugin.java new file mode 100644 index 00000000..18dbd6af --- /dev/null +++ b/buildSrc/src/main/java/org/springframework/graphql/build/ConventionsPlugin.java @@ -0,0 +1,55 @@ +/* + * Copyright 2020-2021 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 + * + * https://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.springframework.graphql.build; + +import io.spring.javaformat.gradle.FormatTask; +import io.spring.javaformat.gradle.SpringJavaFormatPlugin; +import org.gradle.api.Plugin; +import org.gradle.api.Project; +import org.gradle.api.artifacts.DependencySet; +import org.gradle.api.plugins.JavaBasePlugin; +import org.gradle.api.plugins.quality.CheckstyleExtension; +import org.gradle.api.plugins.quality.CheckstylePlugin; + +/** + * Conventions that are applied in the presence of the {@link JavaBasePlugin}. When the + * plugin is applied, the {@link SpringJavaFormatPlugin Spring Java Format} and + * {@link CheckstylePlugin Checkstyle}. + * + * @author Brian Clozel + */ +public class ConventionsPlugin implements Plugin { + + @Override + public void apply(Project project) { + project.getPlugins().withType(JavaBasePlugin.class, (java) -> applySpringJavaFormat(project)); + } + + private void applySpringJavaFormat(Project project) { + project.getPlugins().apply(SpringJavaFormatPlugin.class); + project.getTasks().withType(FormatTask.class, (formatTask) -> formatTask.setEncoding("UTF-8")); + project.getPlugins().apply(CheckstylePlugin.class); + CheckstyleExtension checkstyle = project.getExtensions().getByType(CheckstyleExtension.class); + checkstyle.setToolVersion("8.43"); + checkstyle.getConfigDirectory().set(project.getRootProject().file("src/checkstyle")); + String version = SpringJavaFormatPlugin.class.getPackage().getImplementationVersion(); + DependencySet checkstyleDependencies = project.getConfigurations().getByName("checkstyle").getDependencies(); + checkstyleDependencies + .add(project.getDependencies().create("io.spring.javaformat:spring-javaformat-checkstyle:" + version)); + } + +} diff --git a/src/checkstyle/checkstyle-suppressions.xml b/src/checkstyle/checkstyle-suppressions.xml new file mode 100644 index 00000000..f21b4613 --- /dev/null +++ b/src/checkstyle/checkstyle-suppressions.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/checkstyle/checkstyle.xml b/src/checkstyle/checkstyle.xml new file mode 100644 index 00000000..9475dbe7 --- /dev/null +++ b/src/checkstyle/checkstyle.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/checkstyle/import-control.xml b/src/checkstyle/import-control.xml new file mode 100644 index 00000000..24f501bc --- /dev/null +++ b/src/checkstyle/import-control.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file