diff --git a/build.gradle b/build.gradle
index 5db7b0218ee..fe69e3f9bff 100644
--- a/build.gradle
+++ b/build.gradle
@@ -79,6 +79,7 @@ apply from: file('gradle/validation/validate-source-patterns.gradle')
 apply from: file('gradle/validation/config-file-sanity.gradle')
 apply from: file('gradle/validation/rat-sources.gradle')
 apply from: file('gradle/validation/owasp-dependency-check.gradle')
+apply from: file('gradle/validation/ecj-lint.gradle')
 
 // Source or data regeneration tasks
 apply from: file('gradle/generation/jflex.gradle')
diff --git a/gradle/validation/ecj-lint.gradle b/gradle/validation/ecj-lint.gradle
new file mode 100644
index 00000000000..37810f62a9d
--- /dev/null
+++ b/gradle/validation/ecj-lint.gradle
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+// This adds 'ecjLint' task.
+
+configure(rootProject) {
+  configurations {
+    ecjDeps
+  }
+
+  dependencies {
+    ecjDeps 'org.eclipse.jdt:ecj:3.19.0'
+  }
+}
+
+allprojects {
+  plugins.withType(JavaPlugin) {
+    // Create a [sourceSetName]EcjLint task for each source set
+    // with a non-empty java.srcDirs. These tasks are then
+    // attached to project's "ecjLint" task.
+    def lintTasks = sourceSets.collect { sourceSet ->
+      def srcDirs = sourceSet.java.srcDirs.findAll { dir -> dir.exists() }
+
+      tasks.create("${sourceSet.name}EcjLint", JavaExec, {
+        // This dependency is on a configuration; technically it causes
+        // all dependencies to be resolved before this task executes
+        // (this includes scheduling tasks that compile the
+        // sources from other projects for example).
+        dependsOn sourceSet.compileClasspath
+
+        // We create a task for all source sets but ignore those
+        // that don't have any Java source directories.
+        enabled = !srcDirs.isEmpty()
+
+        classpath = rootProject.configurations.ecjDeps
+        main = "org.eclipse.jdt.internal.compiler.batch.Main"
+
+        // Don't emit any .class files.
+        // Hack around "-d none" still emitting package-info.class
+        // by running in a temporary directory.
+        def tmpDst = getTemporaryDir()
+        workingDir tmpDst
+        args += [ "-d", "none" ]
+
+        // Compilation environment.
+        args += [ "-source", project.java.sourceCompatibility ]
+        args += [ "-target", project.java.targetCompatibility ]
+        args += [ "-encoding", "UTF-8"]
+        args += [ "-nowarn" ]
+
+        doFirst {
+          // Add classpath locations at execution time (can't resolve the
+          // configuration at evaluation time).
+          if (!sourceSet.compileClasspath.isEmpty()) {
+            args += ["-classpath", sourceSet.compileClasspath.asPath]
+          }
+
+          // Add source location(s).
+          // XXX: this doesn't take "excludes" into account (solr-ref-guide trips on it).
+          args += srcDirs
+          // This sadly exceeds max allowed command line size.
+          // args += sourceSet.java.files
+        }
+      })
+    }
+
+    task ecjLint() {
+      description "Lint Java sources using ECJ."
+      group "validation"
+
+      dependsOn lintTasks
+    }
+
+    // Attach ecjLint to check.
+    check.dependsOn ecjLint
+  }
+}
+
+// XXX: Exclude solr-ref-guide from the check (excludes are not taken into account
+// and linting of the ant-based task fails.
+configure(project(":solr:solr-ref-guide")) {
+  afterEvaluate {
+    project.tasks.findByPath("mainEcjLint").enabled = false
+  }
+}
\ No newline at end of file
diff --git a/gradle/validation/precommit.gradle b/gradle/validation/precommit.gradle
index 7ba530e62f2..f98952dcf1d 100644
--- a/gradle/validation/precommit.gradle
+++ b/gradle/validation/precommit.gradle
@@ -39,6 +39,7 @@ configure(rootProject) {
           "licenses",
           "javadoc",
           "rat",
+          "ecjLint"
       ]}
     }
   }
diff --git a/solr/solr-ref-guide/build.gradle b/solr/solr-ref-guide/build.gradle
index 5a40e27ed51..7e6889414a5 100644
--- a/solr/solr-ref-guide/build.gradle
+++ b/solr/solr-ref-guide/build.gradle
@@ -96,6 +96,9 @@ dependencies {
 sourceSets {
     refGuide {
         java {
+            srcDirs = []
+        }
+        resources {
             srcDirs = ['src']
         }
     }
@@ -107,6 +110,12 @@ sourceSets {
             exclude "**/asciidoctor-antlib.xml"
         }
     }
+
+    test {
+        java {
+            srcDirs = []
+        }
+    }
 }
 
 ext {
