You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Rimvydas Vaidelis <ri...@gmail.com> on 2022/03/10 11:50:36 UTC
Dependency version change on dependency import
Hello,
I have a multi-module project and I want to create a bill of materials
(BOM) module. BOM module contains dependencyManagement. My parent module
imports BOM module. BOM module will be used in another project that is
going to use my library. In development environment I would like to change
version of one dependency. I tried to do that using a profile but it seems
that maven does not activate the profile while performing import. Is it a
normal behavior? Maybe you could recommend any other way to implement
dependency version change in development environment.
Thanks in advance for the answers.
Re: Dependency version change on dependency import
Posted by Nils Breunese <ni...@breun.nl>.
Rimvydas Vaidelis <ri...@gmail.com> wrote:
> Thank you for the answer. I know that I can override the dependency version
> in pom that imports the bom module. I wanted to avoid duplicating of the
> dependency overriding in my library and in another project. However now I
> see that it is the only way to implement what I want.
What exactly do you need to duplicate? You could also specify the override version on the dependency directly, without putting it in dependencyManagement, but I personally only manage versions in dependencyManagement, because I often work on multi-module projects and consider that a good practice.
Another way to override a specific dependency would be to have a dedicated Maven property for it, so you’d only have to override that one.
I’m also kind of wondering why you have this use case. Generally when I import a BOM and need a new version of some dependency I just change the version of the whole BOM import, because that is supposed to be a consistent set of modules. Couldn’t you do that instead of overriding only one version from the BOM?
> Actually it was
> strange to me that maven does not respect active profiles on dependency
> import request. Maybe there is a reason why it is like that. It would be
> good if somebody could comment that. Is it by design or it is just
> implemented in this way?
When you use <scope>import</scope> you’re only importing <dependencyManagement> as far as I know, so if there are <profiles> in the BOM those will not be imported.
Nils.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Dependency version change on dependency import
Posted by Rimvydas Vaidelis <ri...@gmail.com>.
Hi Nils,
Thank you for the answer. I know that I can override the dependency version
in pom that imports the bom module. I wanted to avoid duplicating of the
dependency overriding in my library and in another project. However now I
see that it is the only way to implement what I want. Actually it was
strange to me that maven does not respect active profiles on dependency
import request. Maybe there is a reason why it is like that. It would be
good if somebody could comment that. Is it by design or it is just
implemented in this way?
--
Rimvydas
On Sat, Mar 12, 2022 at 2:42 AM Nils Breunese <ni...@breun.nl> wrote:
> Rimvydas Vaidelis <ri...@gmail.com> wrote:
>
> > I have a multi-module project and I want to create a bill of materials
> > (BOM) module. BOM module contains dependencyManagement. My parent module
> > imports BOM module. BOM module will be used in another project that is
> > going to use my library. In development environment I would like to
> change
> > version of one dependency. I tried to do that using a profile but it
> seems
> > that maven does not activate the profile while performing import. Is it a
> > normal behavior? Maybe you could recommend any other way to implement
> > dependency version change in development environment.
>
> I believe you can add a regular dependency entry for the artifact for
> which you want to override the version, like this:
>
> ----
> <dependencyManagement>
> <dependencies>
> <dependency>
> <groupId>com.example</groupId>
> <artifactId>example-bom</artifactId>
> <version>1.0.0</version>
> <type>pom</type>
> <scope>import</scope>
> </dependency>
> <dependency>
> <groupId>com.example</groupId>
> <artifactId>example-artifact-from-bom-i-want-to-override</artifactId>
> <version>1.1.0-SNAPSHOT</version><!-- Overrides version from
> example-bom for this artifact -->
> </dependency>
> </dependencies>
> </dependencyManagement>
>
> <dependencies>
> <dependency>
> <groupId>com.example</groupId>
> <artifactId>example-artifact-managed-by-bom</artifactId>
> </dependency>
> <dependency>
> <groupId>com.example</groupId>
> <artifactId>example-artifact-from-bom-i-want-to-override</artifactId>
> </dependency>
> </dependencies>
> ----
>
> Nils.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
Re: Dependency version change on dependency import
Posted by Nils Breunese <ni...@breun.nl>.
Rimvydas Vaidelis <ri...@gmail.com> wrote:
> I have a multi-module project and I want to create a bill of materials
> (BOM) module. BOM module contains dependencyManagement. My parent module
> imports BOM module. BOM module will be used in another project that is
> going to use my library. In development environment I would like to change
> version of one dependency. I tried to do that using a profile but it seems
> that maven does not activate the profile while performing import. Is it a
> normal behavior? Maybe you could recommend any other way to implement
> dependency version change in development environment.
I believe you can add a regular dependency entry for the artifact for which you want to override the version, like this:
----
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>example-bom</artifactId>
<version>1.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>example-artifact-from-bom-i-want-to-override</artifactId>
<version>1.1.0-SNAPSHOT</version><!-- Overrides version from example-bom for this artifact -->
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>example-artifact-managed-by-bom</artifactId>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>example-artifact-from-bom-i-want-to-override</artifactId>
</dependency>
</dependencies>
----
Nils.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org