Is it possible to access App's version from library project in Spring(with maven)?

65 Views Asked by At

I'm working on a spring (with maven) custom library project. I can access my library project's version ( say 3.0-SNAPSHOT).

How can I access App's version from library project?
I mean the version of the app that uses my custom library project as a library.

3

There are 3 best solutions below

0
user3172755 On

Yes, Of course. First, you need set up nexus server for use. Second, you deploy your app to your private nexus server. You can search maven nexus

0
N4zroth On

Yes, it's possible. The easiest way I found was to introduce a new configuration value in your application.properties like so

[email protected]@

and use it from within your classes like this

@Value("${whatever.value.name:none}")
private String projectVersion;
0
Markoorn On

If your library project references the App root module as a parent:

<parent>
    <groupId>app.group.id</groupId>
    <artifactId>app</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>

You can then reference the project.version property of the app parent in your library with ${project.version} - just make sure you don't have a version defined in the library project otherwise it will use that. If you do want to have a separate library version you can add a property in the parent:

<properties>
    <app.version>1.0.0-SNAPSHOT</app.version>
</properties>

and reference it in the library with ${app.version}