java - Maven: test vs. transitive compile -


this question has answer here:

let's have compile dependency on jar has compile dependency on b. furthermore, tests have dependency on b.

when declare "test" dependency on b, seems override transitive compile dependency on b, cannot compile project anymore. if leave out b, works, feels strange because use transitive dependency directly.

what "maven-like" solution this?

example:

if have

<dependency>   <groupid>commons-httpclient</groupid>   <artifactid>commons-httpclient</artifactid>   <version>3.1</version> </dependency> 

then dependency:list is:

commons-codec:commons-codec:jar:1.2:compile commons-httpclient:commons-httpclient:jar:3.1:compile commons-logging:commons-logging:jar:1.0.4:compile 

the tree is:

      --- maven-dependency-plugin:2.8:tree (default-cli) @ testcompile ---       de.continentale.spu:testcompile:jar:0.0.1-snapshot       \- commons-httpclient:commons-httpclient:jar:3.1:compile          +- commons-logging:commons-logging:jar:1.0.4:compile          \- commons-codec:commons-codec:jar:1.2:compile 

if use

<dependency>   <groupid>commons-httpclient</groupid>   <artifactid>commons-httpclient</artifactid>   <version>3.1</version> </dependency> <dependency>   <groupid>commons-logging</groupid>   <artifactid>commons-logging</artifactid>   <version>1.0.4</version>   <scope>test</scope> </dependency> 

then dependency:list

commons-codec:commons-codec:jar:1.2:compile commons-httpclient:commons-httpclient:jar:3.1:compile commons-logging:commons-logging:jar:1.0.4:test 

the tree is:

--- maven-dependency-plugin:2.8:tree (default-cli) @ testcompile --- de.continentale.spu:testcompile:jar:0.0.1-snapshot +- commons-httpclient:commons-httpclient:jar:3.1:compile |  \- commons-codec:commons-codec:jar:1.2:compile \- commons-logging:commons-logging:jar:1.0.4:test 

so commons-logging changed scope , not available more compilation.

edit2: if use commons-logging in src/main/java, first version compiles while second not. additional test dependency "hides" transitive compile dependency.

have not come across such situation if understood problem version of dependency b required tests , required dependency different. if versions same not have face issue.

in such case, use dependency scope feature provided maven. let dependency dependency b of required version , declare separate dependency b in pom scope test. means usage restricted tests only. can know more here


Comments

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training from India . Nowadays Java has tons of job opportunities on various vertical industry.

    ReplyDelete

Post a Comment

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -