Provided dependencies are deployed in server via Eclipse

Hi guys,

I have a multiple project and the provided scope doesn’t work properly for me.

Here is my project structure:

root
----jar
----war

Here is the build.gradle for the jar:

sourceSets {
    main {
        resources {
            srcDirs 'src/main/resources', 'src/main/webapp'
        }
    }
}
  dependencies {
 'com.sun.faces:jsf-api:2.1.6',
 'com.sun.faces:jsf-impl:2.1.6'
}

Here is the build.gradle for the war:

build.dependsOn(':jar:build')
  apply plugin: 'war'
  dependencies {
 compile project(':jar')
 providedCompile
   'com.sun.faces:jsf-api:2.1.6',
  'com.sun.faces:jsf-impl:2.1.6'
}

And here is the build.gradle for the root of the project:

allprojects {
    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'eclipse-wtp'
          version = '1.3-GRADLE'
    group = 'gradle'
  }

My problem is the next:

When I build the project, all work fine, the war is build without provided dependencies.

But when I import it in Eclipse (indigo), the war is deploy in the server with all dependencies.

So I can’t test my war into Eclipse.

What’s wrong in my configuration ?

Thanks.

One thing that’s wrong is the ‘dependencies’ block of the Jar project. It’s missing a configuration name, which essentially makes it empty. I assume this is a copy paste error.

Another thing that’s wrong is ‘build.dependsOn(’:jar:build’)’. This should be removed.

Regarding the Eclipse problem, it would help to know what the Eclipse projects’ dependencies are, and whether they are marked as exported.

It’s not a copy error. What is wrong about configuration name ? I look at the sample and I don’t see my error.

For the eclipse problem, here is the .classpath (for the war) generated by gradle:

<classpath>
 <classpathentry kind="output" path="bin"/>
 <classpathentry kind="src" path="src/main/java"/>
 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" exported="true"/>
 <classpathentry kind="src" path="/jar" exported="true"/>
 <classpathentry sourcepath="/Users/Kiva/.gradle/caches/artifacts-8/filestore/com.sun.faces/jsf-api/2.1.6/source/9ba8167a79854eab641aaad8ace2b02333015f06/jsf-api-2.1.6-sources.jar" kind="lib" path="/Users/Kiva/.gradle/caches/artifacts-8/filestore/com.sun.faces/jsf-api/2.1.6/jar/191d5b27e7a818c82c3b354349461e6d2eae27e2/jsf-api-2.1.6.jar" exported="true"/>
 <classpathentry sourcepath="/Users/Kiva/.gradle/caches/artifacts-8/filestore/com.sun.faces/jsf-impl/2.1.6/source/ebf265ccf425756d2381e21e87b5aec542144187/jsf-impl-2.1.6-sources.jar" kind="lib" path="/Users/Kiva/.gradle/caches/artifacts-8/filestore/com.sun.faces/jsf-impl/2.1.6/jar/363599f2518713e1b08d2e9625fd8744e14bc516/jsf-impl-2.1.6.jar" exported="true"/>
</classpath>

Here is the .classpath for the jar:

<classpath>
        <classpathentry kind="output" path="bin"/>
        <classpathentry kind="src" path="src/main/java"/>
        <classpathentry kind="src" path="src/main/webapp"/>
        <classpathentry kind="src" path="src/main/resources"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" exported="true"/>
        <classpathentry sourcepath="/Users/Kiva/.gradle/caches/artifacts-8/filestore/com.sun.faces/jsf-api/2.1.6/source/9ba8167a79854eab641aaad8ace2b02333015f06/jsf-api-2.1.6-sources.jar" kind="lib" path="/Users/Kiva/.gradle/caches/artifacts-8/filestore/com.sun.faces/jsf-api/2.1.6/jar/191d5b27e7a818c82c3b354349461e6d2eae27e2/jsf-api-2.1.6.jar" exported="true">
                <attributes>
                        <attribute name="org.eclipse.jst.component.dependency" value="../"/>
                </attributes>
        </classpathentry>
        <classpathentry sourcepath="/Users/Kiva/.gradle/caches/artifacts-8/filestore/com.sun.faces/jsf-impl/2.1.6/source/ebf265ccf425756d2381e21e87b5aec542144187/jsf-impl-2.1.6-sources.jar" kind="lib" path="/Users/Kiva/.gradle/caches/artifacts-8/filestore/com.sun.faces/jsf-impl/2.1.6/jar/363599f2518713e1b08d2e9625fd8744e14bc516/jsf-impl-2.1.6.jar" exported="true">
                <attributes>
                        <attribute name="org.eclipse.jst.component.dependency" value="../"/>
                </attributes>
        </classpathentry>

The dependencies block is missing a configuration name (e.g.‘compile’). As it stands now, the build script won’t even compile:

* What went wrong:
Could not compile build file '/swd/tmp/missingconfig/build.gradle'.
> startup failed:
  build file '/swd/tmp/missingconfig/build.gradle': 4: unexpected token: com.sun.faces:jsf-api:2.1.6 @ line 4, column 5.
         'com.sun.faces:jsf-api:2.1.6',
         ^
      1 error

Ok, I hadn’t understand what you want to say with name ^^. Indeed, it’s a bad copy.

To avoid this (normally I have many dependencies in my project), I create a very small project to reproduce the problem.

So, I restart with the entire files. I test and all compile.

Here is the settings.gradle:

include 'jar', 'war'

Here is the root build.gradle:

allprojects {
    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'eclipse-wtp'
    version = '1.3-GRADLE'
    group = 'gradle'
   repositories {
     mavenCentral()
 }
}

Here is the jar build.gradle:

sourceSets {
    main {
        resources {
            srcDirs 'src/main/resources', 'src/main/webapp'
        }
    }
}
dependencies {
    compile 'com.sun.faces:jsf-api:2.1.6',
    'com.sun.faces:jsf-impl:2.1.6'
}

Here is the war build.gradle:

apply plugin: 'war'
dependencies {
    compile project(':jar')
    providedCompile 'com.sun.faces:jsf-api:2.1.6',
'com.sun.faces:jsf-impl:2.1.6'
}

Have you tried to mark the Jar’s dependencies as not exported in Eclipse?

If I uncheck jsf jars in the export view, nothing change. They are published into the server.

Another potential solution is ‘eclipse.classpath.minusConfigurations’. See the DSL reference for details.

Can you give a sample of this solution ?

Thanks.

Ok I have made some test to find the problem.

The problem come from jar. If I remove the compile project jar into the war, jsf-api and impl aren’t deployed. The provided scope work fine.

But If I add my jar project which brings jsf, jsf jar are deployed into the server. I can’t use provided scope into the jar.

Is it a bug into gradle ? It doesn’t read the classpath from jar to exclude provided dependencies ?

Thanks