Good day,
I've just tried creating a simple plugin named maven-my-dep-plugin to add a
dependency to my maven project.
package personals.samples.plugins;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
/**
* @goal add
*
* @phase initialize
*/
public class AddMojo
extends AbstractMojo
{
/**
* @parameter expression="${dep.groupId}"
* @required
*/
private String depGroupId;
/**
* @parameter expression="${dep.artifactId}"
* @required
*/
private String depArtifactId;
/**
* @parameter expression="${dep.version}"
* @required
*/
private String depVersion;
/**
* @parameter expression="${project}"
* @required
*/
private MavenProject mavenProject;
public void execute()
throws MojoExecutionException
{
Dependency dep = new Dependency();
dep.setGroupId( depGroupId );
dep.setArtifactId( depArtifactId );
dep.setVersion( depVersion );
mavenProject.getDependencies().add( dep );
}
}
With this i can do
mvn my-dep:add eclipse:eclipse -Ddep.groupId=my.group
-Ddep.artifactId=my-artifact -Ddep.version=1.0
and i can see in the generated .classpath the dependency i added...
<classpath>
...
<classpathentry kind="var"
path="M2_REPO/my/group/my-artifact/1.0/my-artifact-1.0.jar"/>
...
</classpath>
Cheers,
Franz
Goel, Deepak wrote:
>
> Thanks again - I had tried this option before and it didn't work. After
> looking at the source, the issue seems that Eclipse does the dependency
> resolution and doesn't look at project.getDependencies() for classpath
> calculation.
>
> When it does the resolution, the packaging comes as .zip and not .jar
> and then it doesn't gets added to the classpath.
>
> Is there any example where such a strategy is being used i.e. a zip file
> that has a jar file that then gets added to classpath?
>
> -----Original Message-----
> From: franz see [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, April 11, 2007 10:35 PM
> To: [EMAIL PROTECTED]
> Subject: RE: Multiple artifacts
>
>
> Pardon,
>
> [1] is
> http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-eclipse-plugin
>
> :)
>
>
> franz see wrote:
>>
>> Good day,
>>
>> After a quick browse through the eclipse plugin's code ( see [1] ),
> I'd
>> suggest you do a getProject().getDependencies().addAll( <your
>> dependencies> ). It seems to be using getProject().getDependencies()
> as a
>> basis for the eclipse project generation.
>>
>> I am not sure though the difference between dependencies and
>> dependencyArtifacts ( aside from the former being a List<Dependency>
> while
>> the latter a Set<Artifact>), and how to properly use them :)
>>
>> Cheers,
>> Franz
>>
>>
>> Goel, Deepak wrote:
>>>
>>> Thanks Franz for your answer - yes, you understood the problem
>>> perfectly. I had gone through the debugger and noticed that
> setArtifacts
>>> was getting called after my plug-in was called.
>>>
>>> I have solved the problem (partially) by adding the Jar file to
>>> DependencyArtifacts in MavenProject. This works for compile but
> doesn't
>>> work for Eclipse project generation.
>>>
>>> How can I solve Eclipse project issue?
>>>
>>> -----Original Message-----
>>> From: franz see [mailto:[EMAIL PROTECTED]
>>> Sent: Tuesday, April 10, 2007 8:07 PM
>>> To: [EMAIL PROTECTED]
>>> Subject: Re: Multiple artifacts
>>>
>>>
>>> Good day,
>>>
>>> AFAIU, you have a single maven project that packages several binaries
>>> and
>>> adds them to the classpaths via a plugin that you've created. But the
>>> binary
>>> that you add via your plugin gets overriden by the binary added via
>>> maven's
>>> transitive dependency....Did I get that right?
>>>
>>> Curious, what made you think that that binary gets overriden? Maybe
> your
>>> classpath issue is a plugin specific problem ( i.e. a plugin only
> uses
>>> the
>>> classpath maven made and not yours ).
>>>
>>> Cheers,
>>> Franz
>>>
>>>
>>> Goel, Deepak wrote:
>>>>
>>>> I have a project that builds multiple artifacts - a jar, a DLL and
>>>> others that are shared by the Jar and DLL. For various reasons, we
>>> have
>>>> decided to create a single POM that has plug-ins in right phases to
>>>> build the DLL.
>>>>
>>>>
>>>>
>>>> So we decided to package this as a ZIP that gets unzipped at the
> right
>>>> time. We also have a plug-in that adds the Jar file as a dependency.
>>> The
>>>> issue is that dependency on Jar file gets overwritten during
>>> transitive
>>>> dependency resolution. Interestingly, the direct dependencies aren't
>>>> affected.
>>>>
>>>>
>>>>
>>>> For example, if there's a project C that depends on B. B in turn
>>> depends
>>>> on A. When I compile C, B.jar remains in the classpath but A.jar
> gets
>>>> removed. I have verified that the plug-in indeed adds A.jar.
>>>>
>>>>
>>>>
>>>> I'll appreciate if somebody can help me resolve this issue.
>>>>
>>>>
>>>>
>>>> Deepak Goel | Small Business Division, Intuit | direct - (650)
>>> 944-3287
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Multiple-artifacts-tf3550158s177.html#a9932478
>>> Sent from the Maven - Users mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>>
>>>
>>
>>
>
> --
> View this message in context:
> http://www.nabble.com/Multiple-artifacts-tf3550158s177.html#a9953320
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
--
View this message in context:
http://www.nabble.com/Multiple-artifacts-tf3550158s177.html#a9962245
Sent from the Maven - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]