You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Nalini <na...@huawei.com> on 2012/02/16 12:29:28 UTC

Copy two versions of same jar

Hi,

 

Can I copy two different versions of same jar using Maven?

 

PS: These two jars have the same groupid and artifact id..

 

Thanks and Regards,

Nalini P G


Re: Copy two versions of same jar

Posted by Barrie Treloar <ba...@gmail.com>.
On Fri, Feb 17, 2012 at 2:51 PM, Wayne Fay <wa...@gmail.com> wrote:
>> <dependencies>
>>       <dependency>
>>           <groupId>test</groupId>
>>           <artifactId>castor</artifactId>
>>           <version>0.9.5</version>
>>       </dependency>
>>       <dependency>
>>           <groupId>test</groupId>
>>           <artifactId>castor</artifactId>
>>           <version>1.0.4</version>
>>       </dependency>
>> </dependencies>
> ...
>> But this copies only one version and it ignores the other one.. Please
>> provide a solution for copying both the versions.
>
> Why do you want to do this? As you've already discovered, Maven will
> generally "collapse" two such dependencies into a single element and
> pick one version over the other.

Can I recommend you read one of the freely available books?
http://maven.apache.org/articles.html

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


RE: Copy two versions of same jar

Posted by "Lyons, Roy" <Ro...@cmegroup.com>.
or...  if you REALLY want to cheat the system (yes, this is terrible, but we do have a certain use case for it).  We put some jar files inside a zip file so that we could make the zip a dependency and it wouldn't be added to the classpath of the application.  These jars are used by an ant process to interpolate variables on the target host to match values expected for the environment (port and IP for example).

I am also morally obligated to warn you that including both versions is hazardous to your health.  You can't exactly specify the order in which they are resolved on the classpath -- and so you never know which class definition will really be resolved first.

If this is to resolve an issue where a dependency of yours needs a newer version, but you use an older version -- I would say that you either have to use a version of the dependency that uses that older version, or you need to update your code to handle the newer version.  It's pretty dangerous to just stick both versions in and cross your fingers.

Disclaimer aside, here is what we do:

        <dependency>
            <groupId>com.companyname</groupId>
            <artifactId>antdeploymentjars</artifactId>
            <version>01</version>
            <type>zip</type>
        </dependency>




		<dependencySet>
			<includes>
				     <include>com.companyname:antdeploymentjars:zip:01</include>		        
			</includes>
					<outputDirectory>deployment/Ant</outputDirectory>
					<unpack>true</unpack>
		</dependencySet>


-----Original Message-----
From: Stephen Connolly [mailto:stephen.alan.connolly@gmail.com] 
Sent: Friday, February 17, 2012 2:28 AM
To: Maven Users List
Subject: Re: Copy two versions of same jar

Alternatively, if you just need a copy of the jar, and not the jar on the classpath, ie you are writing some app that builds its own classpath, some parts of the app use one version and other parts use the other version, and you have fancy code that sets up the class loaders correctly, this would be an ideal illustration of why dependency:copy can be needed sometimes (ie dependency:copy-dependencies does not fit this use-case)

Though IMHO I would rather wrap the code that needs the older version in a separate jar that uses maven-shade-plugin to remove the need for class loader trickery, if you have your own plugin framework, that might not be tractable...

Having said all that, 99% chance is that none of the above apply to your case, and you are just fighting maven because you think you can win... Well you won't win.

On Friday, 17 February 2012, Wayne Fay <wa...@gmail.com> wrote:
>> <dependencies>
>>       <dependency>
>>           <groupId>test</groupId>
>>           <artifactId>castor</artifactId>
>>           <version>0.9.5</version>
>>       </dependency>
>>       <dependency>
>>           <groupId>test</groupId>
>>           <artifactId>castor</artifactId>
>>           <version>1.0.4</version>
>>       </dependency>
>> </dependencies>
> ...
>> But this copies only one version and it ignores the other one.. 
>> Please provide a solution for copying both the versions.
>
> Why do you want to do this? As you've already discovered, Maven will 
> generally "collapse" two such dependencies into a single element and 
> pick one version over the other.
>
> If you have any ability to control the GA coordinates or to add a C
> (classifier) to one of the artifacts, you should do so as that would 
> be the easiest possible solution. Then Maven would consider them as 
> "different" and you could bring in both versions very easily.
>
> Wayne
>
> ---------------------------------------------------------------------
> 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: Copy two versions of same jar

Posted by Stephen Connolly <st...@gmail.com>.
Alternatively, if you just need a copy of the jar, and not the jar on the
classpath, ie you are writing some app that builds its own classpath, some
parts of the app use one version and other parts use the other version, and
you have fancy code that sets up the class loaders correctly, this would be
an ideal illustration of why dependency:copy can be needed sometimes (ie
dependency:copy-dependencies does not fit this use-case)

Though IMHO I would rather wrap the code that needs the older version in a
separate jar that uses maven-shade-plugin to remove the need for class
loader trickery, if you have your own plugin framework, that might not be
tractable...

Having said all that, 99% chance is that none of the above apply to your
case, and you are just fighting maven because you think you can win... Well
you won't win.

On Friday, 17 February 2012, Wayne Fay <wa...@gmail.com> wrote:
>> <dependencies>
>>       <dependency>
>>           <groupId>test</groupId>
>>           <artifactId>castor</artifactId>
>>           <version>0.9.5</version>
>>       </dependency>
>>       <dependency>
>>           <groupId>test</groupId>
>>           <artifactId>castor</artifactId>
>>           <version>1.0.4</version>
>>       </dependency>
>> </dependencies>
> ...
>> But this copies only one version and it ignores the other one.. Please
>> provide a solution for copying both the versions.
>
> Why do you want to do this? As you've already discovered, Maven will
> generally "collapse" two such dependencies into a single element and
> pick one version over the other.
>
> If you have any ability to control the GA coordinates or to add a C
> (classifier) to one of the artifacts, you should do so as that would
> be the easiest possible solution. Then Maven would consider them as
> "different" and you could bring in both versions very easily.
>
> Wayne
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: Copy two versions of same jar

Posted by Wayne Fay <wa...@gmail.com>.
> <dependencies>
> 	<dependency>
> 	    <groupId>test</groupId>
> 	    <artifactId>castor</artifactId>
> 	    <version>0.9.5</version>
> 	</dependency>
> 	<dependency>
> 	    <groupId>test</groupId>
> 	    <artifactId>castor</artifactId>
> 	    <version>1.0.4</version>
> 	</dependency>
> </dependencies>
...
> But this copies only one version and it ignores the other one.. Please
> provide a solution for copying both the versions.

Why do you want to do this? As you've already discovered, Maven will
generally "collapse" two such dependencies into a single element and
pick one version over the other.

If you have any ability to control the GA coordinates or to add a C
(classifier) to one of the artifacts, you should do so as that would
be the easiest possible solution. Then Maven would consider them as
"different" and you could bring in both versions very easily.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


RE: Copy two versions of same jar

Posted by Ansgar Konermann <an...@googlemail.com>.
Am 17.02.2012 04:51 schrieb "Nalini" <na...@huawei.com>:
>
> <dependencies>
>        <dependency>
>            <groupId>test</groupId>
>            <artifactId>castor</artifactId>
>            <version>0.9.5</version>
>        </dependency>
>        <dependency>
>            <groupId>test</groupId>
>            <artifactId>castor</artifactId>
>            <version>1.0.4</version>
>        </dependency>
> </dependencies>

Maven performs *conflict resolution* here. That means: if your dependencies
only differ by the version number, maven will pick *one* as dependency and
drop all other versions of the same groupId/artifactId.

>
> This is how my dependencies are declared. To use copy-dependencies
plug-in,

I guess you use the *goal* copy-dependencies of the
maven-dependency-plugin. Is this correct?

> I did something like
>  <execution>
>            <id>copy-to-lib</id>
>            <phase>validate</phase>
>            <goals>
>              <goal>copy-dependencies</goal>
>            </goals>
>            <configuration>
>                   <includeArtifactIds>caster</ includeArtifactIds>
>              <outputDirectory>${lib-location}</outputDirectory>
>              <overWriteReleases>false</overWriteReleases>
>              <overWriteSnapshots>false</overWriteSnapshots>
>              <stripVersion>false</stripVersion>
>              <excludeTransitive>true</excludeTransitive>
>            </configuration>
>  </execution>
>
> But this copies only one version and it ignores the other one.. Please
provide a solution for copying both the versions.

Have a look at the documentation of maven-dependency-plugin: under *Goals*,
read the section about goal *copy*. Learn how to specify the artifacts you
want to copy using <artifactItems>. There is no conflict resolution applied
to these items, only to maven dependencies.

Hope this helps

Ansgar

>
> Thanks and Regards,
> Nalini P G
>
> -----Original Message-----
> From: Wayne Fay [mailto:waynefay@gmail.com]
> Sent: Thursday, February 16, 2012 9:18 PM
> To: Maven Users List
> Subject: Re: Copy two versions of same jar
>
> > Can I copy two different versions of same jar using Maven?
> >
> > PS: These two jars have the same groupid and artifact id..
>
> Yes, you can since the V part of GAV is different.
>
> If you want a more detailed answer, please provide a more detailed
question.
>
> Wayne
>
> ---------------------------------------------------------------------
> 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: Copy two versions of same jar

Posted by Nalini <na...@huawei.com>.
<dependencies>
	<dependency>
	    <groupId>test</groupId>
	    <artifactId>castor</artifactId>
	    <version>0.9.5</version>
	</dependency>
	<dependency>
	    <groupId>test</groupId>
	    <artifactId>castor</artifactId>
	    <version>1.0.4</version>
	</dependency>
</dependencies>

This is how my dependencies are declared. To use copy-dependencies plug-in, I did something like 
  <execution>
            <id>copy-to-lib</id>
            <phase>validate</phase>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <configuration>
		   <includeArtifactIds>caster</ includeArtifactIds>
              <outputDirectory>${lib-location}</outputDirectory>
              <overWriteReleases>false</overWriteReleases>
              <overWriteSnapshots>false</overWriteSnapshots>
              <stripVersion>false</stripVersion>
              <excludeTransitive>true</excludeTransitive>
            </configuration>
 </execution>

But this copies only one version and it ignores the other one.. Please provide a solution for copying both the versions.

Thanks and Regards,
Nalini P G

-----Original Message-----
From: Wayne Fay [mailto:waynefay@gmail.com] 
Sent: Thursday, February 16, 2012 9:18 PM
To: Maven Users List
Subject: Re: Copy two versions of same jar

> Can I copy two different versions of same jar using Maven?
>
> PS: These two jars have the same groupid and artifact id..

Yes, you can since the V part of GAV is different.

If you want a more detailed answer, please provide a more detailed question.

Wayne

---------------------------------------------------------------------
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: Copy two versions of same jar

Posted by Wayne Fay <wa...@gmail.com>.
> Can I copy two different versions of same jar using Maven?
>
> PS: These two jars have the same groupid and artifact id..

Yes, you can since the V part of GAV is different.

If you want a more detailed answer, please provide a more detailed question.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org