Quantcast

Accessing the version of a dependency

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Accessing the version of a dependency

juranta
Hi,

I'm quite new to Maven, so I'm happy with all suggestions.

So, I have an assembly project which creates an assembly of dependencies. It works fine, but I still miss one piece. I need to get the version of one particular dependency and use it while filtering some files.

I mean, let's say that in the dependencies there's a module A with version 2. I want to filter some files so that parts of them get replaced with "2". For instance, if the original file has the string "My version is ${version}", it should become "My version is 2".

How would I do this in Maven?

I thought of AntRun plugin. Can I access the version of some dependency from Ant? Is there some other solution? Do I need to write a plugin?

Thanks,

Juha
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Accessing the version of a dependency

Ron Wheeler
On 04/01/2011 1:10 PM, juranta wrote:

> Hi,
>
> I'm quite new to Maven, so I'm happy with all suggestions.
>
> So, I have an assembly project which creates an assembly of dependencies. It
> works fine, but I still miss one piece. I need to get the version of one
> particular dependency and use it while filtering some files.
>
> I mean, let's say that in the dependencies there's a module A with version
> 2. I want to filter some files so that parts of them get replaced with "2".
> For instance, if the original file has the string "My version is
> ${version}", it should become "My version is 2".
>
Why do you want to do this?
There may be a better way to filter the files or organize them into
projects.
Ron
> How would I do this in Maven?
>
> I thought of AntRun plugin. Can I access the version of some dependency from
> Ant? Is there some other solution? Do I need to write a plugin?
>
> Thanks,
>
> Juha


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Accessing the version of a dependency

juranta
> Why do you want to do this?
> There may be a better way to filter the files or organize them into
> projects.

It's a big corporation project. A set of web files (images, javascript, css) need to be set in their own directory with each build so that when the customer opens an old document, it will look the same as it used to. That's why I need to dynamically set the url of the document so that it will refer to the files with which it was published.

Juha
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Accessing the version of a dependency

Ron Wheeler
On 04/01/2011 1:35 PM, juranta wrote:
>> Why do you want to do this?
>> There may be a better way to filter the files or organize them into
>> projects.
> It's a big corporation project. A set of web files (images, javascript, css)
> need to be set in their own directory with each build so that when the
> customer opens an old document, it will look the same as it used to. That's
> why I need to dynamically set the url of the document so that it will refer
> to the files with which it was published.
>
Still not clear how the files and versions link up.
If you can describe the desired directory structure after the build and
what the source structure looks like, perhaps someone might be able to
suggest how the assembly plug-in or some other plug-in might be able to
build what you want. This might require some changes to the source
structure but perhaps not.

It sounds like something that has a simple solution but perhaps I do not
see some complexity that has not been revealed.


> Juha


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Accessing the version of a dependency

juranta
>
> Still not clear how the files and versions link up.
> If you can describe the desired directory structure after the build and
> what the source structure looks like, perhaps someone might be able to
> suggest how the assembly plug-in or some other plug-in might be able to
> build what you want. This might require some changes to the source
> structure but perhaps not.
>
> It sounds like something that has a simple solution but perhaps I do not
> see some complexity that has not been revealed.

OK, here goes. I'll try to simplify as much as possible. :)

One of the modules is basically an archive full of css and some other stuff. Let's say this module is A.

In the assembly project there's a dependency on this module A. Let's say the version of A is 2. The assembly project unpacks the module A so that the directory structure looks like this:

css/2/mycss.css
css/2/anothercss.css
css/2/thirdcss.css
....

Of cource, when there's more builds and deployments, there will be a directory structure such as:

css/2/mycss.css
css/2/anothercss.css
css/2/thirdcss.css
....

css/3/mycss.css
css/3/anothercss.css
css/3/thirdcss.css
....

css/4/mycss.css
css/4/anothercss.css
css/4/thirdcss.css
....


In each assembly build, I need to filter an html file "index.xml" so that a tag becomes the version of A. So, in the "index.html", the string "url='${cssversion}'" should become "url='2'" or whatever dependency was used during the assembly.

Thanks,

Juha
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Accessing the version of a dependency

kaosko
In reply to this post by juranta
Assembly plugin can do resource filtering, see
http://maven.apache.org/plugins/maven-assembly-plugin/examples/single/filtering-some-distribution-files.html.

Kalle


On Tue, Jan 4, 2011 at 10:10 AM, juranta <[hidden email]> wrote:

>
> Hi,
>
> I'm quite new to Maven, so I'm happy with all suggestions.
>
> So, I have an assembly project which creates an assembly of dependencies. It
> works fine, but I still miss one piece. I need to get the version of one
> particular dependency and use it while filtering some files.
>
> I mean, let's say that in the dependencies there's a module A with version
> 2. I want to filter some files so that parts of them get replaced with "2".
> For instance, if the original file has the string "My version is
> ${version}", it should become "My version is 2".
>
> How would I do this in Maven?
>
> I thought of AntRun plugin. Can I access the version of some dependency from
> Ant? Is there some other solution? Do I need to write a plugin?
>
> Thanks,
>
> Juha
> --
> View this message in context: http://maven.40175.n5.nabble.com/Accessing-the-version-of-a-dependency-tp3327490p3327490.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Accessing the version of a dependency

juranta
Yes, but my problem is that I need to use the version of one particular dependency while doing the filtering.

Thanks,

Juha

> Assembly plugin can do resource filtering, see
> http://maven.apache.org/plugins/maven-assembly-plugin/examples/single/filtering-some-distribution-
> files.html.

>Kalle
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Accessing the version of a dependency

Ron Wheeler
In reply to this post by juranta
On 04/01/2011 2:23 PM, juranta wrote:

>> Still not clear how the files and versions link up.
>> If you can describe the desired directory structure after the build and
>> what the source structure looks like, perhaps someone might be able to
>> suggest how the assembly plug-in or some other plug-in might be able to
>> build what you want. This might require some changes to the source
>> structure but perhaps not.
>>
>> It sounds like something that has a simple solution but perhaps I do not
>> see some complexity that has not been revealed.
> OK, here goes. I'll try to simplify as much as possible. :)
>
> One of the modules is basically an archive full of css and some other stuff.
> Let's say this module is A.
>
> In the assembly project there's a dependency on this module A. Let's say the
> version of A is 2. The assembly project unpacks the module A so that the
> directory structure looks like this:
>
> css/2/mycss.css
> css/2/anothercss.css
> css/2/thirdcss.css
> ....
>
> Of cource, when there's more builds and deployments, there will be a
> directory structure such as:
>
> css/2/mycss.css
> css/2/anothercss.css
> css/2/thirdcss.css
> ....
>
> css/3/mycss.css
> css/3/anothercss.css
> css/3/thirdcss.css
> ....
>
> css/4/mycss.css
> css/4/anothercss.css
> css/4/thirdcss.css
> ....
>
>
> In each assembly build, I need to filter an html file "index.xml" so that a
> tag becomes the version of A. So, in the "index.html", the string
> "url='${cssversion}'" should become "url='2'" or whatever dependency was
> used during the assembly.
>
> Thanks,
>
> Juha
>
Why not just create a project that has all of the supported versions of
the css files in it with the right index.html files.
They seem to be stable for past releases and the current release would
just evolve until the project was released.
You might not even need the assembly plug-in to build the artifact.

I do not see the big payoff in automating the creation of a single new
URL for each release.

Am I missing something?

Ron


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Accessing the version of a dependency

kaosko
In reply to this post by juranta
Right, and the rest of your build needs to know that version as well,
right? Put that version in a property and use it in the dependency as
well as resource filtering, i.e.
        <properties>
                <cssversion>2</cssversion>
        </properties>

Kalle


On Tue, Jan 4, 2011 at 11:30 AM, juranta <[hidden email]> wrote:

>
> Yes, but my problem is that I need to use the version of one particular
> dependency while doing the filtering.
>
> Thanks,
>
> Juha
>
>> Assembly plugin can do resource filtering, see
>> http://maven.apache.org/plugins/maven-assembly-plugin/examples/single/filtering-some-distribution-
>> files.html.
>
>>Kalle
> --
> View this message in context: http://maven.40175.n5.nabble.com/Accessing-the-version-of-a-dependency-tp3327490p3327642.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Accessing the version of a dependency

Leon Rosenberg
In reply to this post by juranta
Can't you just define the version as variable and use it in your
webresource target path definition?
like in:

      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1</version>
        <configuration>
          ....
          <webResources>
            <resource>
              <!-- this is relative to the pom.xml directory -->
              <directory>mycsssource/</directory>
              <includes><include>**/*.css</include></includes>
              <targetPath>${xyz.version}/</targetPath>
            </resource>
          </webResources>
        </configuration>
      </plugin>


On Tue, Jan 4, 2011 at 8:30 PM, juranta <[hidden email]> wrote:

>
> Yes, but my problem is that I need to use the version of one particular
> dependency while doing the filtering.
>
> Thanks,
>
> Juha
>
>> Assembly plugin can do resource filtering, see
>> http://maven.apache.org/plugins/maven-assembly-plugin/examples/single/filtering-some-distribution-
>> files.html.
>
>>Kalle
> --
> View this message in context: http://maven.40175.n5.nabble.com/Accessing-the-version-of-a-dependency-tp3327490p3327642.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Accessing the version of a dependency

juranta
In reply to this post by kaosko
Thanks, that's a simple solution that might even work in most of the situations (perhaps excepting the release plugin, etc).

 I also found a more complex way to access the versions of a dependency using Groovy plugin. For those who are interested:


         <plugins>
                <plugin>
                    <groupId>org.codehaus.groovy.maven</groupId>
                    <artifactId>gmaven-plugin</artifactId>
                    <version>1.0-rc-5</version>
                    <executions>
                        <execution>
                            <phase>validate</phase>
                            <goals>
                                <goal>execute</goal>
                            </goals>
                            <configuration>
                                <source>
                                                        print project.dependencies;
                                                        for ( i in project.dependencies ) {
                                                                project.properties[ 'depinfo.' + i['groupId'] + '.' + i['artifactId'] + '.version' ] = i['version'];
                                                        }
                                </source>

                            </configuration>
                        </execution>
                    </executions>
                </plugin>

Then you can access ${depinfo.mygroup.myartifact.version}... But I'll try to go with your suggestion.

Juha

> Right, and the rest of your build needs to know that version as well,
> right? Put that version in a property and use it in the dependency as
> well as resource filtering, i.e.
>       <properties> 
>                <cssversion>2</cssversion> 
>        </properties> 
>
> Kalle
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Accessing the version of a dependency

kaosko
On Wed, Jan 5, 2011 at 9:33 AM, juranta <[hidden email]> wrote:
> Thanks, that's a simple solution that might even work in most of the
> situations (perhaps excepting the release plugin, etc).

The release plugin is surprisingly good at dealing with versions
declared in properties, try it, might just work out of the box for
your use case.

Kalle

>
>  I also found a more complex way to access the versions of a dependency
> using Groovy plugin. For those who are interested:
>
>
>         <plugins>
>                <plugin>
>                    <groupId>org.codehaus.groovy.maven</groupId>
>                    <artifactId>gmaven-plugin</artifactId>
>                    <version>1.0-rc-5</version>
>                    <executions>
>                        <execution>
>                            <phase>validate</phase>
>                            <goals>
>                                <goal>execute</goal>
>                            </goals>
>                            <configuration>
>                                <source>
>                                                        print project.dependencies;
>                                                        for ( i in project.dependencies ) {
>                                                                project.properties[ 'depinfo.' + i['groupId'] + '.' +
> i['artifactId'] + '.version' ] = i['version'];
>                                                        }
>                                </source>
>
>                            </configuration>
>                        </execution>
>                    </executions>
>                </plugin>
>
> Then you can access ${depinfo.mygroup.myartifact.version}... But I'll try to
> go with your suggestion.
>
> Juha
>
>> Right, and the rest of your build needs to know that version as well,
>> right? Put that version in a property and use it in the dependency as
>> well as resource filtering, i.e.
>>       <properties>
>>                <cssversion>2</cssversion>
>>        </properties>
>>
>> Kalle
> --
> View this message in context: http://maven.40175.n5.nabble.com/Accessing-the-version-of-a-dependency-tp3327490p3329171.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...