Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
413 views
in Technique[技术] by (71.8m points)

properties - maven - read version number from property file

I`m trying to read my build version number from a text file, and then assign it to the generated package name: myRelease-1.1.1.apk where the build number is manually set into a property file version.number=1.1.1 How can I overload ${version.number} as set in pom.xml by the one in the property file?

Edit: more details about the project . I use git to commit the property file and then Jenkins takes over and builds with Maven. I would like to end up with a build “myBuild-9.9.9.apk”. Right now I have “myBuild-1.1.2.apk” In extras/version.properties

project.version=9.9.9  

In pom.xml

<?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/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <parent>
            .....
            <version>1.1.2</version>
      </parent>

      <groupId>ca.lapresse.android</groupId>
      <artifactId>lapresse-hockey-app</artifactId>
      <packaging>apk</packaging>
      <name>La Presse Hockey - App</name>
      <version>1.1.2</version>

…… It seems that ${project.artifactId} takes the version number from <version></version> and it becomes 1.1.2. This should be reflected in ${project.version}, which I’m trying to overload from the property file.

<plugin>
<groupId>org.codehaus.mojo</groupId>
      <artifactId>properties-maven-plugin</artifactId>
      <version>1.0-alpha-2</version>
      <executions>
            <execution>
                  <phase>process-resources</phase>
                  <goals>
                        <goal>read-project-properties</goal>
                  </goals>
                  <configuration>
                        <files>
                              <file>${project.basedir}/extras/version.properties</file>
                        </files>
                  </configuration>
            </execution>
      </executions>
</plugin>

What am I doing wrong and what I am not doing at all? My understanding of Maven is very rudimentary (I come from an Ant background).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just to answer my own question: it turns out that Maven needs the property to be set before anything can happen in the script. As such, it is set in stone and not modifiable from a file. I ended up writing an Ant task that modifies the pom.xml and changes the version in the file, before Maven script is triggered. Ugly and non-trivial, but it works.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...