0

I need to add the same dependency twice configuring one version for the compilation and test purpose and another version of the same library for the runtime.

It sounds weird and it is wrong but I received 2 version of the same library from another team in my company and the "test purpose" version contains some classes - used only by the "test" methods - that haven't to be expose in a production server because very sensible being part of the 'core'. So this means I need to use a version library for the test and compilation phase and another one only on the server. Actually I solved the problem setting only the "test" version with 'provided' scope, so it won't be included in the generated war, and putting the "production" version in the web container's lib folder but my boss wants I will automate the configuration!!!

Unfortunately if I add the dependency to the second version with 'runtime' or 'compile' scope maven doesn't find the classes present only in the "test" version during the JUnit execution step. It seems like Maven recognises the libraries like the same and the 'compile' or 'runtime' configuration won on the other one. I've tried also to set the "test" version with 'test' scope but it doesn't work either... actually I've tried all the possible combinations using 'test' and 'provided' scopes for the "test" version and 'runtime' and 'compile' for the "production one.

Any suggestion? I can't ask for a different library only for test purposes or just to change the name of the library, everything is integrated with a continuous integration system and it has to be automated with it, so annoying...

    <dependency>
        <groupId>company.group.id</groupId>
        <artifactId>project.id</artifactId>
        <version>0.1.1.TEST</version>
        <scope>provided</scope>
        //<scope>test</scope>
    </dependency>

    <dependency>
        <groupId>company.group.id</groupId>
        <artifactId>project.id</artifactId>
        <version>0.1.0.PROD</version>
        <scope>compile</scope>
        //<scope>runtime</scope>
    </dependency>

Thanks

user3227323
  • 159
  • 2
  • 9

1 Answers1

1

Peter Lawrey says in this link,

"Maven assumes it doesn't make any sense to have more than one version of a module at once. It assumes that a newer version replaces the older version. If it doesn't it is not the same module. I suggest you give the newer module a different name and make sure it has different packages to avoid choising a random module.

In general Maven tried to encourage good application design and deliberately makes it difficult to do things it has determined to be a bad idea."

Community
  • 1
  • 1
Iker Aguayo
  • 3,980
  • 4
  • 37
  • 49
  • -1 this appears plagiaristic. It would have been better to state something like: `Peter Lawrey states:` This questions should have just be closed as duplicate. – John B Nov 12 '14 at 12:24
  • That is why I said, 'see this link', and I copied from this link what I thought that was important. And yes, that could be a duplicated question. But now is corrected – Iker Aguayo Nov 12 '14 at 12:31