Skip to content

Commit 6e8eede

Browse files
committed
Make GRADLE-1116 workaround more generic
Previously the workaround for GRADLE-1116 only worked for the merge-dist.gradle projects Now the workaround is more generic and fixes errors that have since been introduced when performing a fresh import into Eclipse.
1 parent 2ef99cd commit 6e8eede

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

build.gradle

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.gradle.plugins.ide.eclipse.model.ProjectDependency
2+
13
buildscript {
24
repositories {
35
maven { url 'http://repo.springsource.org/plugins-release' }
@@ -8,21 +10,22 @@ buildscript {
810
}
911

1012
configure(allprojects) {
13+
ext.aspectjVersion = '1.6.12'
14+
ext.hsqldbVersion='1.8.0.10'
15+
ext.junitVersion = '4.11.20120805.1225' // temporary use of snapshot; spring-test
16+
// still builds against on 4.10
17+
ext.gradleScriptDir = "${rootProject.projectDir}/gradle"
18+
1119
apply plugin: 'java'
1220
apply plugin: 'eclipse'
1321
apply plugin: 'idea'
22+
apply from: "${gradleScriptDir}/ide.gradle"
1423

1524
group = 'org.springframework'
1625

1726
sourceCompatibility=1.5
1827
targetCompatibility=1.5
1928

20-
ext.aspectjVersion = '1.6.12'
21-
ext.hsqldbVersion='1.8.0.10'
22-
ext.junitVersion = '4.11.20120805.1225' // temporary use of snapshot; spring-test
23-
// still builds against on 4.10
24-
ext.gradleScriptDir = "${rootProject.projectDir}/gradle"
25-
2629
[compileJava, compileTestJava]*.options*.compilerArgs = ['-Xlint:none']
2730

2831
sourceSets.test.resources.srcDirs = ['src/test/resources', 'src/test/java']
@@ -38,13 +41,6 @@ configure(allprojects) {
3841
testCompile "org.hamcrest:hamcrest-all:1.3"
3942
testCompile "org.easymock:easymock:2.5.1"
4043
}
41-
42-
// servlet-api (2.5) and tomcat-servlet-api (3.0) classpath entries should not be
43-
// exported to dependent projects in Eclipse to avoid false compilation errors due
44-
// to changing APIs across these versions
45-
eclipse.classpath.file.whenMerged { classpath ->
46-
classpath.entries.findAll { entry -> entry.path.contains('servlet-api') }*.exported = false
47-
}
4844
}
4945

5046
configure(subprojects - project(":spring-test")) {

gradle/ide.gradle

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import org.gradle.plugins.ide.eclipse.model.ProjectDependency
2+
3+
eclipse.classpath.file.whenMerged { classpath ->
4+
// servlet-api (2.5) and tomcat-servlet-api (3.0) classpath entries should not be
5+
// exported to dependent projects in Eclipse to avoid false compilation errors due
6+
// to changing APIs across these versions
7+
classpath.entries.findAll { entry -> entry.path.contains('servlet-api') }*.exported = false
8+
9+
// GRADLE-1116
10+
def regexp = /.*?\/([^\/]+)\/build\/[^\/]+\/(?:main|test)/ // only match those that end in main or test (avoids removing necessary entries like build/classes/jaxb)
11+
def projectOutputDependencies = classpath.entries.findAll { entry -> entry.path =~ regexp }
12+
projectOutputDependencies.each { entry ->
13+
def matcher = (entry.path =~ regexp)
14+
if(matcher) {
15+
def projectName = matcher[0][1]
16+
def path = "/${projectName}"
17+
if(!classpath.entries.find { e -> e instanceof ProjectDependency && e.path == path }) {
18+
def dependency = new ProjectDependency(path, project(":${projectName}").path)
19+
dependency.exported = true
20+
classpath.entries.add(dependency)
21+
}
22+
classpath.entries.remove(entry)
23+
}
24+
}
25+
classpath.entries.removeAll { entry -> (entry.path =~ /(?!.*?repack.*\.jar).*?\/([^\/]+)\/build\/libs\/[^\/]+\.jar/) }
26+
}

gradle/merge-artifacts.gradle

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import org.gradle.plugins.ide.eclipse.model.ProjectDependency
2-
31
/**
42
* Will merge the artifacts of the current project into mergeIntoProject. For example, to
53
* bundle spring-test-mvc in spring-test's jars. This script will perform the following
@@ -43,14 +41,6 @@ mergeIntoProject."javadoc" {
4341
classpath += mergeFromProject.javadoc.classpath
4442
}
4543

46-
// GRADLE-1116
47-
mergeFromProject.eclipse.classpath.file.whenMerged { classpath ->
48-
classpath.entries.removeAll { entry -> entry.path.contains("/${mergeIntoProject.name}/build/") }
49-
def dependency = new ProjectDependency("/${mergeIntoProject.name}", mergeIntoProject.path)
50-
dependency.exported = true
51-
classpath.entries.add(dependency)
52-
}
53-
5444
// Update mergeIntoProject to contain additional configurations that contains all the dependencies from mergeFromProject
5545
// so that Maven pom generation works
5646
gradle.taskGraph.whenReady {

0 commit comments

Comments
 (0)