You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by DenisDasKind <bl...@abv.bg> on 2014/05/14 16:41:27 UTC
Version in Mojo
Hi,
i'm new to maven, and now i have the following problem. I have a custom
Mojo, and the Mojo should print the own version stored in the pom.xml of
this mojo. And now i have trouble to get this version. I have tried the
project.version, but this is always the version of the pom, that calls my
Mojo. A easy way, will be when the version is hardcoded, but this is not the
best way, becausae each time when the version is changed (release) i must
change it manually.
Is there a better way to get this version?
Thank you in advance!
--
View this message in context: http://maven.40175.n5.nabble.com/Version-in-Mojo-tp5793054.html
Sent from the Maven - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Version in Mojo
Posted by Martin Hoeller <ma...@xss.co.at>.
Am Wed, 14 May 2014 07:41:27 -0700 (PDT) schrieb DenisDasKind <bl...@abv.bg>:
> Hi,
>
> i'm new to maven, and now i have the following problem. I have a
> custom Mojo, and the Mojo should print the own version stored in the
> pom.xml of this mojo. And now i have trouble to get this version. I
> have tried the project.version, but this is always the version of the
> pom, that calls my Mojo. A easy way, will be when the version is
> hardcoded, but this is not the best way, becausae each time when the
> version is changed (release) i must change it manually.
> Is there a better way to get this version?
There are also some useful hints on StackOverflow:
http://stackoverflow.com/questions/2712970/how-to-get-maven-artifact-version-at-runtime/12571330
hth,
- martin
Re: Version in Mojo
Posted by Bernd Eckenfels <ec...@zusammenkunft.net>.
Hello,
this is not really Mojo specific.
If you build a JAR with maven you can
include the build number or version with filtered resources, filtering
the source code, as a expanded Variable in the Manifest header or by
copy of META-INF/maven/pom.properties. To any of those information you
can then reference to print it out.
This is an example I use (you need to use a class of your project and
add maven group and artifactID):
/** Read program version from Manifest or maven properties. */
private static String getVersion()
{
Class me = MyClass.class;
Package jarPackage = me.getPackage();
if (jarPackage != null)
{
String version = jarPackage.getImplementationVersion();
if (version != null)
{
return version;
}
}
InputStream in =
me.getClassLoader().getResourceAsStream("META-INF/maven/groupID/artifactID/pom.properties");
if (in == null) { return "UNKNOWN";}
try
{
Properties p = new Properties();
p.load(in);
return p.getProperty("version", "UNKNOWN");
}
catch (Exception ignored)
{
return "UNKNOWN";
}
finally
{
try { in.close(); } catch (Exception ignored) { /* ignored
*/ } }
}
Greetings
Bernd
Am Wed, 14 May 2014 07:41:27 -0700
(PDT) schrieb DenisDasKind <bl...@abv.bg>:
> Hi,
>
> i'm new to maven, and now i have the following problem. I have a
> custom Mojo, and the Mojo should print the own version stored in the
> pom.xml of this mojo. And now i have trouble to get this version. I
> have tried the project.version, but this is always the version of the
> pom, that calls my Mojo. A easy way, will be when the version is
> hardcoded, but this is not the best way, becausae each time when the
> version is changed (release) i must change it manually.
> Is there a better way to get this version?
>
> Thank you in advance!
>
>
>
> --
> View this message in context:
> http://maven.40175.n5.nabble.com/Version-in-Mojo-tp5793054.html Sent
> from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Version in Mojo
Posted by Dan Tran <da...@gmail.com>.
or you can get your plugin build to dump the version into a resource file
and read it at mojo exec time
On Wed, May 14, 2014 at 11:19 AM, Dan Tran <da...@gmail.com> wrote:
> Your plugin manifest has that info ( look under your jar/META-INF)
>
> -D
>
>
> On Wed, May 14, 2014 at 7:41 AM, DenisDasKind <bl...@abv.bg> wrote:
>
>> Hi,
>>
>> i'm new to maven, and now i have the following problem. I have a custom
>> Mojo, and the Mojo should print the own version stored in the pom.xml of
>> this mojo. And now i have trouble to get this version. I have tried the
>> project.version, but this is always the version of the pom, that calls my
>> Mojo. A easy way, will be when the version is hardcoded, but this is not
>> the
>> best way, becausae each time when the version is changed (release) i must
>> change it manually.
>> Is there a better way to get this version?
>>
>> Thank you in advance!
>>
>>
>>
>> --
>> View this message in context:
>> http://maven.40175.n5.nabble.com/Version-in-Mojo-tp5793054.html
>> Sent from the Maven - Users mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
>
Re: Version in Mojo
Posted by Dan Tran <da...@gmail.com>.
Your plugin manifest has that info ( look under your jar/META-INF)
-D
On Wed, May 14, 2014 at 7:41 AM, DenisDasKind <bl...@abv.bg> wrote:
> Hi,
>
> i'm new to maven, and now i have the following problem. I have a custom
> Mojo, and the Mojo should print the own version stored in the pom.xml of
> this mojo. And now i have trouble to get this version. I have tried the
> project.version, but this is always the version of the pom, that calls my
> Mojo. A easy way, will be when the version is hardcoded, but this is not
> the
> best way, becausae each time when the version is changed (release) i must
> change it manually.
> Is there a better way to get this version?
>
> Thank you in advance!
>
>
>
> --
> View this message in context:
> http://maven.40175.n5.nabble.com/Version-in-Mojo-tp5793054.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
Re: Version in Mojo
Posted by Manfred Moser <ma...@mosabuam.com>.
Store the version of the plugin in a properties file and load it at runtime..
DenisDasKind wrote on 14.05.2014 07:41:
> Hi,
>
> i'm new to maven, and now i have the following problem. I have a custom
> Mojo, and the Mojo should print the own version stored in the pom.xml of
> this mojo. And now i have trouble to get this version. I have tried the
> project.version, but this is always the version of the pom, that calls my
> Mojo. A easy way, will be when the version is hardcoded, but this is not the
> best way, becausae each time when the version is changed (release) i must
> change it manually.
> Is there a better way to get this version?
>
> Thank you in advance!
>
>
>
> --
> View this message in context:
> http://maven.40175.n5.nabble.com/Version-in-Mojo-tp5793054.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org