3

I am creating a multi module project with Spring Boot for deploying my application and using gradle as my build tool.

Now, I am creating independent deployments for some modules in the project. Some of the project requires Embedded tomcat and some do not. All the common dependencies have been put on a common project and all other modules are dependent on this common project.

Most of the other deployment modules require an embedded tomcat application server and other web components (provided by org.springframework.boot', name: 'spring-boot-starter-web) so this has been included in the build.gradle for common project

Here is the build.gradle for common project:

compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: springBootVersion compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: springBootVersion compile group: 'org.springframework.data', name: 'spring-data-jpa', version: springDataJpaVersion 

Now, one of the other modules which is going to be deployed independently does not require this embedded tomcat and other mvc jars which comes with including spring-boot-starter-web but requires the other transitive dependencies from common project. As such, I want to exclude the transitive dependency for

 compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion 

I am doing it like this in the build.gradle other project

dependencies { compile project(':common') { exclude group 'org.springframework.boot', module:'spring-boot-starter-web' } } 

But while building it is throwing this error:

startup failed: build file '/Users/user1/Documents/repo/storm/build.gradle': 30: expecting '}', found ',' @ line 30, column 44. oup 'org.springframework.boot', module:'

changing it to:

dependencies { compile project(':common'){ exclude group 'org.springframework.boot:spring-boot-starter-web' } } 

throws:

Could not find method exclude() for arguments [parent-project name] on project ':common'.

How can I exclude transitive dependency here?

1 Answer 1

4

You need to invoke exclude on compile not on project:

dependencies { compile(project(':common')) { exclude group: 'org.springframework.boot', module:'spring-boot-starter-web' } } 
Sign up to request clarification or add additional context in comments.

8 Comments

What does it mean didn't work? It fails or dependencies are not excluded?
Sorry for not being explicit . It failed to compile and i got error as Could not find method exclude() for arguments [parent-project name] on project ':common'. However , When I changed the build file and did below : configurations { compile.exclude module: 'org.springframework.boot' compile.exclude group : 'spring-boot-starter-web' } The project compiled but still When I run my application , it starts an embedded tomcat . I dont want embedded tomcat to start and my application to run over tomcat ? Any ideas how to do this .
Ah yes.. There's not exclude method on project instance. Have you tried: stackoverflow.com/questions/13923516/… ?
Opal , I think setting transitive = false will exclude all dependencies of subproject whereas I only want specific dependencies to be excluded (importantly , I dont want tomcat to be started :( and my application to be deployed on it ).
I'm not sure if you can exclude project dependencies partially :/
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.