diff --git a/.gitignore b/.gitignore index fd6449f1c7c4c..0163712c89559 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ out/ !.idea/scopes/x_pack.xml !.idea/inspectionProfiles/Project_Default.xml !.idea/runConfigurations/Debug_Elasticsearch.xml +!.idea/checkstyle-idea.xml # These files are generated in the main tree by IntelliJ benchmarks/src/main/generated/* diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000000000..75cca1a8171f4 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d9cea81c08a06..fda0adce688fd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -174,27 +174,9 @@ file is generated automatically after IntelliJ finishes syncing. You can manually generate the file with `./gradlew configureIdeCheckstyle` in case it is removed due to a `./gradlew clean` or other action. - 1. Open **Preferences > Tools > Checkstyle** - 2. We have some custom Checkstyle rules, and the Checkstyle plugin needs - to know where to find them. Under the "Third-Party Checks" section, - click the "+" button. - 3. Select `buildSrc/build-bootstrap/libs/buildSrc-$VERSION.jar` where - `$VERSION` is something like `7.0.0-SNAPSHOT`. This jar file will - always exist if you imported the project into IntelliJ before - configuring Checkstyle. - 4. Make sure that "Checkstyle version" is set to the highest available version - 5. Change the "Scan Scope" to "Only Java sources (including tests)" - 6. Click the "+" under "Configuration file" - 7. Set "Description" to "Elasticsearch" - 8. Select "Use a local Checkstyle file" - 9. For the "File", enter `checkstyle_ide.xml` - 10. Tick "Store relative to project location" - 11. Click "Next", then "Finish". - 12. Click the box next to the new configuration to make it "Active". - Without doing this, you'll have to explicitly choose the - "Elasticsearch" configuration in the Checkstyle tool window and run - the check manually. - 13. Click "OK" to apply the new preferences +IntelliJ should be automatically configured to use the generated rules after +import via the `.idea/checkstyle-idea.xml` configuration file. No further +action is required. #### Formatting diff --git a/build-conventions/build.gradle b/build-conventions/build.gradle index f703ef70febe7..e55ea0086cc1c 100644 --- a/build-conventions/build.gradle +++ b/build-conventions/build.gradle @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import org.gradle.plugins.ide.eclipse.model.SourceFolder; +import org.gradle.plugins.ide.eclipse.model.SourceFolder plugins { id 'java-gradle-plugin' @@ -56,6 +56,7 @@ dependencies { api 'org.apache.maven:maven-model:3.6.2' api 'gradle.plugin.com.github.jengelman.gradle.plugins:shadow:7.0.0' api 'org.apache.rat:apache-rat:0.11' + compileOnly "com.puppycrawl.tools:checkstyle:8.42" } project.getPlugins().withType(JavaBasePlugin.class, javaBasePlugin -> { diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/checkstyle/MissingJavadocTypeCheck.java b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/checkstyle/MissingJavadocTypeCheck.java similarity index 100% rename from build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/checkstyle/MissingJavadocTypeCheck.java rename to build-conventions/src/main/java/org/elasticsearch/gradle/internal/checkstyle/MissingJavadocTypeCheck.java diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/checkstyle/SnippetLengthCheck.java b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/checkstyle/SnippetLengthCheck.java similarity index 100% rename from build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/checkstyle/SnippetLengthCheck.java rename to build-conventions/src/main/java/org/elasticsearch/gradle/internal/checkstyle/SnippetLengthCheck.java diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckstylePrecommitPlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckstylePrecommitPlugin.java index d2baacc114451..582fb2e4e0df5 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckstylePrecommitPlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckstylePrecommitPlugin.java @@ -11,7 +11,6 @@ import org.elasticsearch.gradle.VersionProperties; import org.elasticsearch.gradle.internal.InternalPlugin; import org.elasticsearch.gradle.internal.conventions.precommit.PrecommitPlugin; -import org.elasticsearch.gradle.internal.conventions.util.Util; import org.gradle.api.Action; import org.gradle.api.GradleException; import org.gradle.api.Project; @@ -19,6 +18,7 @@ import org.gradle.api.artifacts.dsl.DependencyHandler; import org.gradle.api.plugins.quality.Checkstyle; import org.gradle.api.plugins.quality.CheckstyleExtension; +import org.gradle.api.provider.Provider; import org.gradle.api.tasks.TaskProvider; import java.io.File; @@ -88,8 +88,9 @@ public void execute(Task task) { DependencyHandler dependencies = project.getDependencies(); String checkstyleVersion = VersionProperties.getVersions().get("checkstyle"); + Provider dependencyProvider = project.provider(() -> "org.elasticsearch:build-conventions:" + project.getVersion()); dependencies.add("checkstyle", "com.puppycrawl.tools:checkstyle:" + checkstyleVersion); - dependencies.add("checkstyle", project.files(getBuildSrcCodeSource())); + dependencies.addProvider("checkstyle", dependencyProvider, dep -> dep.setTransitive(false)); project.getTasks().withType(Checkstyle.class).configureEach(t -> { t.dependsOn(copyCheckstyleConf); diff --git a/build-tools-internal/src/testKit/elasticsearch.build/build.gradle b/build-tools-internal/src/testKit/elasticsearch.build/build.gradle index 72dc7e1a4c735..4bcd3d4cd2140 100644 --- a/build-tools-internal/src/testKit/elasticsearch.build/build.gradle +++ b/build-tools-internal/src/testKit/elasticsearch.build/build.gradle @@ -68,3 +68,5 @@ tasks.register("hello") { println "build plugin can be applied" } } +// requires further classpath +tasks.named("checkstyleMain").configure {enabled = false }