3

Trying to read version from properties file but getting below exception

  1. Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:properties-maven-plugin:1.0-alpha-2:read-project-properties (execution: default, phase: initialize)
  2. Missing artifact org.springframework.cloud:spring-cloud-starter-zipkin:jar:${zipkin-version}

Below is the pom.xml and properties file

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.0.RELEASE</version>
        <relativePath /> 
    </parent>
    <groupId>com.wtw</groupId>
    <artifactId>Demo Project</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>AlertNotification</name>
    <description>Demo</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
                <version>1.0-alpha-2</version>
                <executions>
                    <execution>
                        <phase>initialize</phase>
                        <goals>
                            <goal>read-project-properties</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <files>
                        <file>C:\Workspace\version.properties</file>
                    </files>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>           
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
    
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zipkin</artifactId>
            <version>${zipkin-version}</version>
        </dependency>
        
    </dependencies> 

</project>




version.properties file
zipkin-version=2.2.2.RELEASE
Shiladittya Chakraborty
  • 4,270
  • 8
  • 45
  • 94
  • Does this answer your question? [Specify pom properties via a properties file?](https://stackoverflow.com/questions/27987065/specify-pom-properties-via-a-properties-file) – talex Jul 13 '20 at 07:30

2 Answers2

4

Dependencies are resolved before plugins are executed.

So the properties you read with the properties-maven-plugin are not available in the <dependencies> section.

If you want to set a dependency version by property, this property must be set inside the POM, on the command line or in the settings.xml.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • Means I need to put all the properties file in settings.xml? or is there any way to put external properties file in settings.xml? if you please give one example it will be very helpful – Shiladittya Chakraborty Jul 13 '20 at 09:16
  • No, you cannot put external files into the `settings.xml` and I am not sure it is sensible to put the properties there. What exactly to you want to achieve? Who should supply the version? Why is it not set in the POM? – J Fabian Meier Jul 13 '20 at 10:22
  • I have 4 5 module which are individual module they don't have any parent module So every module having same jar mostly so trying jar version in some common place so that I dont need to mentain jar version for each and every module, I need to maintain in single place which is properties file. And I will refer this properties file in all module – Shiladittya Chakraborty Jul 13 '20 at 10:25
  • Why not use a BOM for this? You can put dependencyManagement into the BOM and then `import` the BOM in all your projects. – J Fabian Meier Jul 13 '20 at 10:37
  • Can you please give one example for that?? It will be really help me – Shiladittya Chakraborty Jul 13 '20 at 10:38
  • https://howtodoinjava.com/maven/maven-bom-bill-of-materials-dependency/ – J Fabian Meier Jul 13 '20 at 10:41
  • The link shows you how to import BOMs. If you look at one of those BOMs, you see how to write them. – J Fabian Meier Jul 13 '20 at 10:42
  • Can we store BOM file at some common place.. So that I can import it from there – Shiladittya Chakraborty Jul 13 '20 at 11:02
  • The BOM is a separate project that you build. It also has a version number that you reference in the different POMs that reference the BOM. – J Fabian Meier Jul 13 '20 at 11:04
  • Each project has it’s own maven bom file Please note that there is no common or universal bom file. Each project (if support this feature) provides its own bom file and manages versions of it’s related dependencies. Means bom file we need to create project wise not in common place? – Shiladittya Chakraborty Jul 13 '20 at 11:49
  • I thought you wanted to have the same versions in all projects? Then my advice would be to use one BOM for all projects. – J Fabian Meier Jul 13 '20 at 13:21
  • No.. I want to put all jar version in some file like properties file and kept it in some common or universal place and get jar version from properties file. So we dont need to maintain for each pom file – Shiladittya Chakraborty Jul 13 '20 at 13:26
  • Yes, that it what BOMs are for. You put all jar versions into the BOM, build it, and then reference it in each project. – J Fabian Meier Jul 13 '20 at 13:44
  • How? do I need to maintain BOM for each module and put all jar version over there? If you put one demo then it will realy help me – Shiladittya Chakraborty Jul 13 '20 at 13:47
  • As per BOM instructed that "no common or universal bom file".. Thats why I confused – Shiladittya Chakraborty Jul 13 '20 at 13:49
  • You start a new Maven project. This only contains a `pom.xml`. Here, you add the versions you want to manage as `dependencyManagement` entries. Then you build it. This is your BOM. Then you `import` the BOM in all your projects as described in my link above. So there is one BOM for all your project and it does not lie in any of them, but forms a separate one. – J Fabian Meier Jul 13 '20 at 13:50
  • Ok understood.. suppose we have created one demo project for bom adn added version 4.0.1.RELEASE in bom file. Now how to access this in other module? Like I need to include this demo project then I can access right? – Shiladittya Chakraborty Jul 13 '20 at 14:11
  • 1
    You build the BOM first `mvn install`, and then use the BOM with the correct version in your other project. – J Fabian Meier Jul 13 '20 at 14:42
  • Thank you.. Can you please help me with one more issue https://stackoverflow.com/questions/62881433/dependency-not-resolved-from-bom-file Tried to load version from BOM file but some how its not working.. Can you please look into this question – Shiladittya Chakraborty Jul 13 '20 at 18:09
-1

You are using an old version of the plugin (1.0-alpha-2), update it to the latest 1.0.0.

Then make sure that the file version.properties is in the folder C:\Workspace. Anyway, with the latest version of the plugin you should get a proper error message if it can't find the file.

One more suggestion: spring-cloud-starter-zipkin belongs to the org.springframework.cloud group which follows another version. The suggested way to declare that dependency is like the following:

<properties>
    <java.version>1.8</java.version>
    <spring-cloud.version>Hoxton.SR6</spring-cloud.version>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <!-- ... -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-zipkin</artifactId>
    </dependency>
    <!-- ... -->
</dependencies>
Marc
  • 2,738
  • 1
  • 17
  • 21