0

When i exeute: mvn -Dparam.version=9 help:effective-pom | clip in the command line on Windows 10 i get all over this clip only:

<properties>
      <param.version>4</param.version>
</properties> 

which is the old version. How can i force to change this param?

In the cmd:

mvn --version
Apache Maven 3.5.4

Froms poms:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
</plugin>

EDIT: I use this property to set depedency version for example:

<dependency>
    <groupId>x</groupId>
    <artifactId>c-api/artifactId>
    <version>${param.version}</version>
</dependency>

inside c-api we can see:

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>x</groupId>
        <artifactId>c</artifactId>
        <version>4</version>
    </parent>

    <artifactId>c-api</artifactId>
    <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>x</groupId>
            <artifactId>c-api</artifactId>
        </dependency>

        <dependency>
            <groupId>x</groupId>
            <artifactId>p-api</artifactId>
        </dependency>

        <dependency>
            <groupId>x</groupId>
            <artifactId>f-api</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-commons</artifactId>
        </dependency>

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
tryingHard
  • 1,794
  • 4
  • 35
  • 74
  • Perhaps you need to use `mvn -Djava.version=9 ...`? – Steve C Dec 04 '18 at 13:18
  • @SteveC no - let's suggest the name of parameter is `param` it is not related to `java` version. From which version is this `overriding` feature avaiable ? – tryingHard Dec 04 '18 at 13:19
  • According to https://stackoverflow.com/questions/33130388/replace-maven-properties-in-pom-xml-via-command-line that should work, so maybe there is something you do differently? – Wim Deblauwe Dec 04 '18 at 13:26
  • Sorry, the presence of the `maven-compiler-plugin` configuration is completely irrelevant then. Please add the section of your pom where `${param.version}` is evaluated. – Steve C Dec 04 '18 at 13:26
  • I added an example where i use my param – tryingHard Dec 04 '18 at 13:29
  • Another thing is that `c` pom is from `.m2/repository` right now. – tryingHard Dec 04 '18 at 13:45
  • 1
    According to what you have above, the x:c:4 artifact is in fact a parent pom, so the dependency example you added will fail because it does not refer to a jar. Are you trying to parameterise the version of the parent of the x:c-api:4 artifact? – Steve C Dec 04 '18 at 13:53
  • I'm sorry - i try to change childs version to be excact: `c-api/artifactId>` my bad - i'm sorry. I fixed the question. `c-api` is child of `c`. This was a `typo`. I meant before `c-api` – tryingHard Dec 04 '18 at 14:01

2 Answers2

1

First, you need use -Dparam.version instead -dParam.version.

If

<properties>
    <param.version>4</param.version>
</properties

is defined in the xxx.pom file, you are not allowed to change it using command line, while you are free to override it. And in this case, though the value is still 4 in the pom file, others which refer it by ${param.version} will pick 9.

xingbin
  • 27,410
  • 9
  • 53
  • 103
  • that's intresting. Still the main pom has old version though and this maybe my issue. – tryingHard Dec 04 '18 at 13:31
  • @yami This might help. https://stackoverflow.com/questions/13708738/how-to-get-a-command-line-property-to-overwrite-a-maven-property – xingbin Dec 04 '18 at 13:33
  • yeah i got a lot of `${param.version}` in my project i edited the question. The question is that stuff `X` reads the old value somewhere. I do not see elsewhere `param.version` set to `4` manually (only in the properties of main pom once). – tryingHard Dec 04 '18 at 13:37
  • `First, you need use -Dparam.version instead -dParam.version.` yeah, I use the first one. – tryingHard Dec 04 '18 at 13:40
1

You are looking in the incorrect place when checking if your command line parameter has been correctly applied.

If you entered the command mvn -Dparam.version=9 help:effective-pom then you should see your dependency version evaluated correctly.

Where your pom has

...
<dependency>
    <groupId>x</groupId>
    <artifactId>c-api</artifactId>
    <version>${param.version}</version>
</dependency>
...

the output of the command will display

...
<dependency>
    <groupId>x</groupId>
    <artifactId>c-api</artifactId>
    <version>9</version>
</dependency>
...

If you just run mvn help:effective-pom you will see

...
<dependency>
    <groupId>x</groupId>
    <artifactId>c-api</artifactId>
    <version>4</version>
</dependency>
...

with the version specified in the pom properties displayed instead.

Steve C
  • 18,876
  • 5
  • 34
  • 37
  • That's an answer for an upvote. Still i checked in `war` from `target` folder in `tomcat/lib` and some versions are old. If i type newer version in main pom manually (like `9`) then i got good versions in war from `target` in `tomcat/lib` the core of my issue is not resolved by this answer and as i posted in the question i tried to run `mvn -Dparam.version=9 help:effective-pom` not `help:effective-pom` to check faster versions. I want the versions to be the same when changing param version with `mvn clean install` just like in the case when i change version manually in the main pom. – tryingHard Dec 04 '18 at 14:42
  • So you understood it clearly: 1) If I change version manually to let's say `9` in main pom - everything is ok, all libs from `war` file located in `target` folder are ok. 2) When i try to change versions by additional param to `mvn clean install` like `mvn -Dparam.version=9` the versions in the libs are not ok - they are still `4` - the old ones. – tryingHard Dec 04 '18 at 14:49
  • If it's not working for you then there is something else going on. I have tested this. Note that you cannot modify the dependency versions if they have not been defined as a property in the first place. – Steve C Dec 04 '18 at 14:58
  • What do you mean? I have `4` as `property` and use it in depedency `version` like `${param.version}`. The `c-api` is only placed as `` – tryingHard Dec 04 '18 at 15:01