Conditional import of Java class based on dependency version

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Conditional import of Java class based on dependency version

Jagat Singh
Hi,

I wanted to learn what is the pattern in maven when we have to change the
import at the top of class based on dependency version.

Example in Java code

If dependency version is 1.0
Then import path

import com.hello.Class

If dependency version is 2.0
Then import path

import com.hello2.Class


Thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: Conditional import of Java class based on dependency version

Benjamin Marwell
Well, if the Dependency version changed with the target java  Bytecode
version, you could create a multirelease jar and manage the dependencies
via profiles.

But that would seem not feasible to me.
What's your use case?
Or maybe you could refactor that class(es) into modules instead?

Best regards,
Ben




On Tue, 9 Jun 2020, 13:51 Jagat Singh, <[hidden email]> wrote:

> Hi,
>
> I wanted to learn what is the pattern in maven when we have to change the
> import at the top of class based on dependency version.
>
> Example in Java code
>
> If dependency version is 1.0
> Then import path
>
> import com.hello.Class
>
> If dependency version is 2.0
> Then import path
>
> import com.hello2.Class
>
>
> Thanks in advance.
>