Try to fix the gradle compilation in idea (#945)

* Try to fix the gradle compilation in idea
* Try to detect sync and build phases within intellij and act accordingly to support both modes of compilation (gradle and intellij).
This commit is contained in:
Dawid Weiss 2022-06-09 11:14:10 +02:00 committed by GitHub
parent 1dceff12c8
commit 54c67db10d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 14 deletions

View File

@ -15,16 +15,16 @@
* limitations under the License.
*/
// Try to detect IntelliJ model loader ("reimport") early.
rootProject.ext.isIdea = System.getProperty("idea.active") != null ||
gradle.startParameter.taskNames.contains('idea') ||
gradle.startParameter.taskNames.contains('cleanIdea')
// Try to detect IntelliJ model loader project structure "sync"
//
rootProject.ext.isIdea = Boolean.parseBoolean(System.getProperty("idea.active", "false"))
rootProject.ext.isIdeaSync = Boolean.parseBoolean(System.getProperty("idea.sync.active", "false"))
rootProject.ext.isIdeaBuild = (isIdea && !isIdeaSync)
if (isIdea) {
logger.warn("IntelliJ Idea IDE detected.")
}
allprojects {
allprojects {
apply plugin: 'idea'
idea {
@ -34,4 +34,27 @@ allprojects {
downloadSources = true
}
}
}
}
if (isIdeaBuild) {
// Skip certain long tasks that are dependencies
// of 'assemble' if we're building from within IntelliJ.
gradle.taskGraph.whenReady { taskGraph ->
def tasks = taskGraph.getAllTasks()
def skipTasks = [
// Skip site javadoc rendering
".*:(renderSiteJavadoc)",
]
logger.lifecycle("Skipping certain tasks on IntelliJ builds")
tasks.each { task ->
def taskPath = task.path
if (skipTasks.any { pattern -> taskPath ==~ pattern }) {
logger.debug("Skipping task on IntelliJ: " + taskPath)
task.enabled = false
}
}
}
}

View File

@ -76,7 +76,7 @@ allprojects {
// LUCENE-10304: if we modify the classpath here, IntelliJ no longer sees the dependencies as compile-time
// dependencies, don't know why.
if (!rootProject.ext.isIdea) {
if (!rootProject.ext.isIdeaSync) {
task.classpath = modularPaths.compilationClasspath
}
@ -119,7 +119,7 @@ allprojects {
// LUCENE-10304: if we modify the classpath here, IntelliJ no longer sees the dependencies as compile-time
// dependencies, don't know why.
if (!rootProject.ext.isIdea) {
if (!rootProject.ext.isIdeaSync) {
def jarTask = project.tasks.getByName(mainSourceSet.getJarTaskName())
def testJarTask = project.tasks.getByName(testSourceSet.getJarTaskName())