Forcing a module version has no effect on generated org.eclipse.wst.common.component


(David Resnick) #1

I have a multi-project build some projects that depend on hibernate-core 3.6.8-Final, which in turn depends on commons-collections 3.1.

I overrode this transitive dependency with the following in all java projects:

configurations {
 all {
  resolutionStrategy.force "commons-collections:commons-collections:3.2.1"
 }
}

This works fine for all plugins (java, tomcat, war), though it fails to be applied in the case of the eclipse-wtp plugin. The original 3.1 jar is referenced in the generated .settings/org.eclipse.wst.common.component as a dependent-module instead of version 3.2.1.

Thanks for any help!

–David


(Peter Niederwieser) #2

Did you do a ‘cleanEclipse’?


(David Resnick) #3

Yes.


(Peter Niederwieser) #4

This reproduces the problem:

apply plugin: "war"
apply plugin: "eclipse-wtp"
  repositories {
  mavenCentral()
}
  dependencies {
  compile "org.hibernate:hibernate-core:3.6.8.Final"
}
  configurations {
    all {
        resolutionStrategy.force "commons-collections:commons-collections:3.2.1"
    }
}

Creating a JIRA issue.


(David Resnick) #5

Thanks Peter!


(Klaus Baumgartner) #6

I have another example that is quite probably related. Excludes by configuration don’t work either with eclipse-wtp (using gradle version 1.2). For excludes by dependency (see commented lines below) eclipse-wtp behaves as expected.

With SpringSource inlining a class-incompatible spring-asm into spring-core with version 3.2.0.M2 pretty soon there might be a good amount of gradle-users interested in this:

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'war'
  repositories {
        mavenCentral()
}
  configurations {
        runtime.exclude module:'spring-asm'
}
  dependencies {
        runtime
       'org.springframework:spring-beans:3.1.2.RELEASE'
//
    runtime
       ('org.springframework:spring-beans:3.1.2.RELEASE') {
//
            exclude module:'spring-asm'
//
    }
           testCompile
   'junit:junit:4.10'
}

All excludes in this example have an effect on .classpath. Only the commented exclude has an effect on .settings/org.eclipse.wst.common.component.


(Klaus Baumgartner) #7

I dug into gradle sources a bit, and - with close to zero knowledge about the internal matters of gradle -

this is what seems to fix the problem that eclipse-wtp ignores excludes by configuration.

@Peter: This does not seem to be the solution to GRADLE-2496, although it fixes my excluded dependencies issue. What is the correct way to get my concern/possible solution into issue tracking?

From d92af380146e34af1781b78a15770032708a88ed Mon Sep 17 00:00:00 2001
From: illusioni <klaus@illusioni.de>
Date: Sat, 6 Oct 2012 00:37:25 +0200
Subject: [PATCH] With little knowledge about the internal matters of gradle -
 this is what seems to fix the problem that eclipse-wtp
 ignores excludes by configuration
  ---
 .../model/internal/WtpComponentFactory.groovy
    |
  9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
  diff --git a/subprojects/ide/src/main/groovy/org/gradle/plugins/ide/eclipse/model/internal/WtpComponentFactory.groovy b/subprojects/ide/src/main/groovy/org/gradle/plugins/ide/eclipse/model/internal/WtpComponentFactory.groovy
index d1ff2e8..32b7c7a 100644
--- a/subprojects/ide/src/main/groovy/org/gradle/plugins/ide/eclipse/model/internal/WtpComponentFactory.groovy
+++ b/subprojects/ide/src/main/groovy/org/gradle/plugins/ide/eclipse/model/internal/WtpComponentFactory.groovy
@@ -16,7 +16,6 @@
 package org.gradle.plugins.ide.eclipse.model.internal
    import org.gradle.api.artifacts.Configuration
-import org.gradle.api.artifacts.Dependency
 import org.gradle.api.artifacts.ExternalDependency
 import org.gradle.api.artifacts.SelfResolvingDependency
 import org.gradle.plugins.ide.eclipse.EclipsePlugin
@@ -24,6 +23,8 @@ import org.gradle.plugins.ide.eclipse.model.EclipseWtpComponent
 import org.gradle.plugins.ide.eclipse.model.WbDependentModule
 import org.gradle.plugins.ide.eclipse.model.WbResource
 import org.gradle.plugins.ide.eclipse.model.WtpComponent
+import org.gradle.plugins.ide.internal.IdeDependenciesExtractor
+import org.gradle.plugins.ide.internal.IdeDependenciesExtractor.IdeRepoFileDependency
    /**
  * @author Hans Dockter
@@ -89,7 +90,11 @@ class WtpComponentFactory {
         Set declaredDependencies = getDependencies(plusConfigurations, minusConfigurations,
                 { it instanceof ExternalDependency})
   -
      Set libFiles = wtp.project.configurations.detachedConfiguration((declaredDependencies as Dependency[])).files +
+
      //Just like in ClasspathFactory this considers excludes by configuration:
+
      List<IdeRepoFileDependency> deps = new IdeDependenciesExtractor().extractRepoFileDependencies(wtp.project.configurations, plusConfigurations, minusConfigurations, false, false)
+
      Set libFiles = deps.collect { IdeRepoFileDependency dep -> dep.file }
+
+
      libFiles = libFiles +
                 getSelfResolvingFiles(getDependencies(plusConfigurations, minusConfigurations,
                         { it instanceof SelfResolvingDependency && !(it instanceof org.gradle.api.artifacts.ProjectDependency)}))
   --
 1.7.9.4

(Szczepan Faber) #8

Hey, Thanks for trying to debug the issue. Do you mind sending a pull request (the above patch does not seem to be correct) for this bugfix?

One other potential workaround is using eclipse tasks’ whenMerged hook to manipulate the final list of the classpath entries.

Hope that helps!


(Klaus Baumgartner) #9

OK, the pull request is sent: https://github.com/gradle/gradle/pull/104

I apologize for mixing this problem with David’s issue. I thought using the common IdeDependenciesExtractor in WtpComponentFactory would take care of both, forced dependencies and excludes by configuration. (But it only solved the latter.)

Cheers!


(Gerhard Schlager) #10

Is there some kind of workaround for this problem that I could apply to my build files until this is fixed in eclipse-wtp? I was so happy when Gradle 1.4 added the new dependency resolve rules which allows something like this.

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.requested.group == 'org.springframework') {
            details.useVersion '3.2.0.RELEASE'
        }
    }
}

Unfortunately eclipse-wtp completly ignores those rules which makes them kinda useless to me.


(Szczepan Faber) #11

There’s no easy workaround I’m afraid. I’ll raise this ticket to the team.

You can try with the whenMerged / withXml hooks (http://www.gradle.org/docs/current/dsl/org.gradle.plugins.ide.eclipse.model.EclipseWtpComponent.html) to manipulate the component content.


(Szczepan Faber) #12

I’ve created new ticket for it: GRADLE-2653

We already have a pull request and it should get applied soon.


(Szczepan Faber) #13

This problem is now fixed in master and should be released with 1.5.