5

For reasons I don't even want to begin to get into.. I have a maven hierarchy that looks like the one below. In a nutshell, everything requires commonslang3, except one ancient artifact that requires commonslang2.

We have no issues with compile or runtime, the dependencies work as expected. The challenge we are having is at development time.

We'd like to ensure everyone on the team uses the commonslang3 APIs, but occasionally (because of the ancient artifact and Eclipse auto suggest), someone accidentally uses the commonslang2 APIs.

Normally, we would just force the desired version in our POM, but commonslang is a special snowflake. The package signature changed between comonslang2 and commonslang3, which means we would have compile failures if we excluded the older library. E.g.,

  • org.apache.commons.lang3.StringUtils
  • org.apache.commons.lang.StringUtils

My question is this, how can I configure maven/Eclipse, to use commonlang2 as needed during compile... but not populate it in the Eclipse class autosuggest list? My desired end state is that someone types 'stringuti' + ctrl + space, and the only option they see is commonslang3. I am aware that each developer can remove individual classes via (Window->Preferences->Java->Appearance->Type Filters) but that is not a viable solution for two reasons: 1) It's a large team with frequently changing resources... 2) I need an entire artifact removed, as in hundreds of classes.

Example Tree:

MyWar
  -- MyModuleJar1
     -- ...
  -- MyModuleJar2
     -- LibA
        -- commonslang
        -- ... 
     -- LibB
        -- commonslang3   
        -- ...
     -- LibC
        -- commonslang3
        -- ...
     -- ...
Skylar Sutton
  • 4,632
  • 3
  • 27
  • 39
  • possible duplicate of [Eclipse: Exclude specific packages when autocompleting a class name](http://stackoverflow.com/questions/2073913/eclipse-exclude-specific-packages-when-autocompleting-a-class-name) – JustinKSU Jul 07 '15 at 16:16
  • Edited to explain why it's not, but thank you. – Skylar Sutton Jul 07 '15 at 16:37
  • Would it be possible to use your code review tool to put in a rule that prevents adding a commons lang reference? – JustinKSU Jul 07 '15 at 18:21
  • Is "Me" a war or ear file? Is there a way to add commonslang to the classpath at runtime? Alternatively could you use the war maven plugin to add commonslang to the web-inf/lib without it being a dependency? This could be done by using the exclusion tag when importing LibA. – JustinKSU Jul 07 '15 at 18:41
  • I updated the dependency tree to clarify what's going on. Top level is a WAR owned by us, containing multiple maven modules (JAR outputs). One of those modules was the original "me", and has dependencies on LibaA, LibB, etc. I'll try out some of the suggestions here when I get out of this meeting and update/resolve accordingly. – Skylar Sutton Jul 07 '15 at 19:31

2 Answers2

1

In Eclipse: Window->Preferences->Java->Appearance->Type Filters

Add org.apache.commons.lang.*

Because you want to affect auto-complete which is a function of the IDE, you are forced to change the setting in the IDE. You can export the preferences and share them of the rest of the team.

JustinKSU
  • 4,875
  • 2
  • 29
  • 51
0

There is not much you can do about it in Eclipse other than type filters @JustinKSU mentioned.

But with Maven you can use Takari to access rules to prevent accidental inclusion of transitive dependencies. Of course this comes with a plethora of caveats with one ironically being that the Eclipse JDT compiler has to be used instead of plain javac.

Adam Gent
  • 47,843
  • 23
  • 153
  • 203