How to display pom version in angular project?

How to display pom version in angular project?
angular
Ethan Jackson

I have an Angular project (Nx monorepo) inside a Maven project. In my Jenkinsfile, the Angular project is built first using buildWorkflow and then workflow is called. I am not familiar with Jenkins so I do not know what both of these functions do. But I have been told that the version number in pom.xml is overwritten in this process. Its placeholder value is 0.1-SNAPSHOT.

I want to display the version number from pom.xml in a component in my Angular project.

Answer

1. Write version to a JSON file during Maven build In your pom.xml, use the maven-resources-plugin to generate a file with the version:

<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>3.2.0</version> <executions> <execution> <phase>process-resources</phase> <goals><goal>copy-resources</goal></goals> <configuration> <outputDirectory>${project.build.directory}/generated</outputDirectory> <resources> <resource> <directory>${basedir}/src/version</directory> <filtering>true</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin> </plugins> </build> Create a file version.json under src/version/: { Load version in Angular import { HttpClient } from '@angular/common/http'; This will let your Angular component dynamically display the version from pom.xml.

Related Articles