0
votes

I have a problem with provided dependency scope. In my multiprojects with structure like below:

ROOT - ear

  • ejb
  • web

Web module depends on ejb.

This is my root build.gradle:

apply plugin: 'ear'
allprojects {
apply plugin: 'java'
apply plugin: 'idea'

configurations {
provided
}

sourceSets {
main {
compileClasspath += configurations.provided
runtimeClasspath += configurations.provided
}
test {
compileClasspath += configurations.provided
runtimeClasspath += configurations.provided
}
}

idea { module { scopes.PROVIDED.plus += [configurations.provided] } }

dependencies{
provided 'javax.enterprise:cdi-api:1.1'
}
}
dependencies{
deploy project(path: ':web', configuration: 'archives')
deploy project(':ejb')
}

}

And in project ejb I defined provided dependencies:

dependencies{
    provided 'javax.ejb:javax.ejb-api:3.2'
    provided 'javax.transaction:javax.transaction-api:1.2'
    provided 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final'
}

In web module:

apply plugin: 'war'

dependencies{
    providedCompile project(':ejb')
    providedCompile 'javax.faces:javax.faces-api:2.2'
    providedCompile 'javax.servlet:javax.servlet-api:3.1.0'

}

When using the Gradle war plugin you're enabled to declare providedCompile dependencies to tell the compiler to include those dependencies in the compile classpath, but to not make Gradle include them in the packaged .war artifact.

But when my custom provided include this dependency to war archive: 'javax.enterprise:cdi-api:1.1'

How Can I resolve my problem? enter image description here

1

1 Answers

2
votes

I solved my problem by adding the following piece of code:

war {
    classpath = classpath - configurations.provided
}