How to exclude a child 'project dependency' from parent when we add parent into another project?


(Imteyaz Ahmad) #1

Example:
This is a multi project build
==================================================================
Test
settings.gradle:
include “:Test-service”, “:Test-persistence”,":Test-security"
==================================================================
Test-service
build.gradle:
dependencies {
compile project (’:Test-persistence’)
compile project (’:Test-security’)
other dependencies
}
==================================================================
Test-security
build.gradle:
dependencies {
compile project (’:Test-persistence’)
other dependencies
==================================================================
Test-persistence
build.gradle:
dependencies {
other dependencies
}
==================================================================

How to exclude "Test-persistence" from "Test-security" when I add it in "Test-service" ?

(Mark Vieira) #2

I’m not sure I understand. Do you want to exclude the transitive dependency of ‘Test-security’? If so, how would that be any different since you are explicitly adding a dependency to ‘Test-persistence’?


(Imteyaz Ahmad) #3

Hi Mark,

Thanks for your reply. There was a mistake in the example. I edited that. For compilation, Test-security and Test-service both use Test-persistence. Also, Test-service uses Test-security. When I am trying to use Test-security in Test-service, I want to exclude Test-persistence which is present in Test-security.


(Mark Vieira) #4

What are you trying to accomplish? Why do you want to exclude that particular project dependency? Excluding ‘Test-persistence’ from ‘Test-security’ will have the same final result since you are explicitly depending on it.


(Imteyaz Ahmad) #5

Hi Mark,

Sorry for the delayed response. I want to exclude Test-persistence from Test-security because when Test-service is getting loaded, the Application is trying to register entity manager for Hibernate twice as it is present in both Test-security and Test-service. Also, I wanted to learn how to exclude a project dependency.


(Mark Vieira) #6

That shouldn’t be the case. The JAR should only be on the classpath once. In any case, you can exclude a project dependency like any other.

    compile(project (':Test-security')) {
        exclude module: 'Test-persistence'
    }

(Uma Sankar) #7

Hi Mark,

I have tried the above approach, but the issue is still exists. Can you please help me to resolve this?