From 298cb22bfecdf8b2655403fac8c3cd60e1214b20 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 23 Nov 2020 17:24:57 +0100 Subject: [PATCH] Ensure that projects can be imported into Eclipse IDE Recently the Spring Framework projects could no longer be imported into Eclipse IDE without compilation errors in JMH sources. This commit addresses this issue by applying workarounds for bugs in Gradle and the JMH plugin for Gradle. Gradle bug: https://github.com/gradle/gradle/issues/14932 JMH plugin bug: https://github.com/melix/jmh-gradle-plugin/issues/157 The Gradle bug has already been fixed in Gradle 6.8 RC1; however, the issue for the JMH plugin bug seems not to have been triaged yet. Closes gh-26140 --- gradle/ide.gradle | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/gradle/ide.gradle b/gradle/ide.gradle index 554d4b3c543..39eefb55c4c 100644 --- a/gradle/ide.gradle +++ b/gradle/ide.gradle @@ -29,12 +29,11 @@ eclipse.classpath.file.whenMerged { classpath -> classpath.entries.removeAll { entry -> (entry.path =~ /(?!.*?repack.*\.jar).*?\/([^\/]+)\/build\/libs\/[^\/]+\.jar/) } } - // Use separate main/test outputs (prevents WTP from packaging test classes) eclipse.classpath.defaultOutputDir = file(project.name+"/bin/eclipse") eclipse.classpath.file.beforeMerged { classpath -> classpath.entries.findAll{ it instanceof SourceFolder }.each { - if(it.output.startsWith("bin/")) { + if (it.output.startsWith("bin/")) { it.output = null } } @@ -56,6 +55,23 @@ eclipse.classpath.file.whenMerged { classpath -> } } +// Ensure that test fixture dependencies are handled properly in Gradle 6.7. +// Bug fixed in Gradle 6.8: https://github.com/gradle/gradle/issues/14932 +eclipse.classpath.file.whenMerged { + entries.findAll { it instanceof ProjectDependency }.each { + it.entryAttributes.remove('without_test_code') + } +} + +// Ensure that JMH sources and resources are treated as test classpath entries +// so that they can see test dependencies such as JUnit Jupiter APIs. +// https://github.com/melix/jmh-gradle-plugin/issues/157 +eclipse.classpath.file.whenMerged { + entries.findAll { it.path =~ /src\/jmh\/(java|resources)/ }.each { + it.entryAttributes['test'] = 'true' + } +} + // Allow projects to be used as WTP modules eclipse.project.natures "org.eclipse.wst.common.project.facet.core.nature"