You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Karl Heinz Marbaise <kh...@gmx.de> on 2017/09/13 19:11:06 UTC

Re: Project dependencies vs plugin dependencies for a mojo looking at the project

Hi Adam,

On 12/09/17 18:05, Adam Hardy wrote:
> 
> Hi,
> 
> when I'm coding a mojo, if I call MavenProject's getArtifacts(), I can only get artifacts from the project level dependencies.
> 
> How do I obtain artifacts from a plugin's dependencies?

The question which comes to my mind: Why do you need the dependencies of 
your own ? Aren't the defined in your plugin's pom ?

Maybe I misunderstand a thing here?


> 
> Presumably I call something like project.getPlugin(key).getDependencies()?
> 
> If the 'key' required for project.getPlugin(key) is of the form myGroup:myPlugin:version e.g. com.megacorp:thing-plugin:1.0.2
> 
> can I get my mojo's own key programmatically in the mojo to avoid hard-coding it?


Can you please explain what you are trying to accomplish ?


> 
> Thanks
> Adam
> 


Kind regards
Karl Heinz Marbaise

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


Re: Project dependencies vs plugin dependencies for a mojo looking at the project

Posted by ahardy42 <ad...@cyberspaceroad.com>.
Karl Heinz Marbaise-3 wrote
>>I thought I could just enter it once as a plugin dependency in
>> the user project pom - assuming it would be the only one.
> 
> You can give this via the plugin configuration and which means your 
> plugin must resolve it's dependencies and make a required download for 
> it...which can be easily done by using a maven-artifact-transfer[3].
> 
> [3]: 
> https://maven.apache.org/shared/maven-artifact-transfer/install-project.html

I wasn't able to get the maven-artifact-transfer to function in my mojo. I
resorted to Aether's RepositorySystem.resolveArtifact() method. 




Karl Heinz Marbaise-3 wrote
>>>> Presumably I call something like 
>>>> project.getPlugin(key).getDependencies()?
>>>>
>>>> If the 'key' required for project.getPlugin(key) is of the form 
>>>> myGroup:myPlugin:version e.g. com.megacorp:thing-plugin:1.0.2
>>>>
>>>> can I get my mojo's own key programmatically in the mojo to avoid 
>>>> hard-coding it?

This is the last issue I'm facing (famous last words.....)

I currently hard-code my plugin's key so I can obtain it while the mojo is
in action:

    Plugin plugin = project.getPlugin("com.megacorp.stuff:my-plugin");
    plugin.getDependencies()......

but I'd like to avoid that in case my successor decides to rename it or
something similar.

How can I the key programmatically, by reaching deep into the mojo?

Regards
Adam



--
Sent from: http://maven.40175.n5.nabble.com/Maven-Users-f40176.html

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


Re: Project dependencies vs plugin dependencies for a mojo looking at the project

Posted by Adam Hardy <ad...@cyberspaceroad.com>.
>> The users of my plugin define a dependency which the mojo unpacks and 
>> extracts certain files from.
>
> You know that such a plugin already exists? maven-dependency-plugin:unpack / 
> unpack-dependencies ?
>
> https://maven.apache.org/plugins/maven-dependency-plugin/examples/unpacking-artifacts.html 
>
>
I knew one must exist, but I hadn't looked at the docs - interesting.

The reason why I wrote it myself was to try to avoid the duplication of 
configuration items, to try to keep it succinct. Otherwise the user would have 
to enter the desired file names twice (or more) - once to extract it, and again 
to feed it into the next mojo where the file contents are used.


> Furthermore the question is why do you need only certain files from it ?

It's a shared configuration file archive used by several projects. Not the 
greatest idea, I know.

> You can give this via the plugin configuration and which means your plugin 
> must resolve it's dependencies and make a required download for it...which can 
> be easily done by using a maven-artifact-transfer[3].
>
> [3]: https://maven.apache.org/shared/maven-artifact-transfer/install-project.html

Yes, true, but to try to keep it all  succinct and intuitive, I figured it is 
best to make it a real dependency from the XML point-of-view.



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


Re: Project dependencies vs plugin dependencies for a mojo looking at the project

Posted by Karl Heinz Marbaise <kh...@gmx.de>.
Hi,

On 13/09/17 23:29, Adam Hardy wrote:
> 
>> On 12/09/17 18:05, Adam Hardy wrote:
>>> when I'm coding a mojo, if I call MavenProject's getArtifacts(), I 
>>> can only get artifacts from the project level dependencies.
>>>
>>> How do I obtain artifacts from a plugin's dependencies?
>>
>> The question which comes to my mind: Why do you need the dependencies 
>> of your own ? Aren't the defined in your plugin's pom ?
>>
>> Maybe I misunderstand a thing here?
>>
>>
>>>
>>> Presumably I call something like 
>>> project.getPlugin(key).getDependencies()?
>>>
>>> If the 'key' required for project.getPlugin(key) is of the form 
>>> myGroup:myPlugin:version e.g. com.megacorp:thing-plugin:1.0.2
>>>
>>> can I get my mojo's own key programmatically in the mojo to avoid 
>>> hard-coding it?
>>
>>
>> Can you please explain what you are trying to accomplish ?
> 
> The users of my plugin define a dependency which the mojo unpacks and 
> extracts certain files from.

You know that such a plugin already exists? 
maven-dependency-plugin:unpack / unpack-dependencies ?

https://maven.apache.org/plugins/maven-dependency-plugin/examples/unpacking-artifacts.html

Furthermore the question is why do you need only certain files from it ?


> 
> At the moment, I have coded the plugin to take the groupId and 
> artifactId of this dependency via the mojo config.

Sounds good so far...so counting one place...

something like this.

<build>
   <plugins>
     <plugin>...
        <groupId>..</groupId>
        </artifactId>..</artifactId>
        <version>..</version>
        <configuration>
          <groupId>Group to be unpacked</groupId>
          <artifactId>artifact of being upackage</artifactId>
          ...
        </configuration>
     </plugin>
   </plugins>
</build>

> 
> This strikes me as doppel gemoppelt

I assume you mean duplicated ? ( I understand that; But only a few 
people here on the list have german background).

> for the user to put that info in
> twice. 

 >I thought I could just enter it once as a plugin dependency in
> the user project pom - assuming it would be the only one.

What do you think will the usage as plugin depenency change ?


You can give this via the plugin configuration and which means your 
plugin must resolve it's dependencies and make a required download for 
it...which can be easily done by using a maven-artifact-transfer[3].

But I don't see the requirement to define it in two place ?

Kind regards
Karl Heinz Marbaise


[1]: 
https://maven.apache.org/plugins/maven-dependency-plugin/unpack-mojo.html
[2]: 
https://maven.apache.org/plugins/maven-dependency-plugin/unpack-dependencies-mojo.html
[3]: 
https://maven.apache.org/shared/maven-artifact-transfer/install-project.html

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


Re: Project dependencies vs plugin dependencies for a mojo looking at the project

Posted by Adam Hardy <ad...@cyberspaceroad.com>.
> On 12/09/17 18:05, Adam Hardy wrote:
>> when I'm coding a mojo, if I call MavenProject's getArtifacts(), I can only 
>> get artifacts from the project level dependencies.
>>
>> How do I obtain artifacts from a plugin's dependencies?
>
> The question which comes to my mind: Why do you need the dependencies of your 
> own ? Aren't the defined in your plugin's pom ?
>
> Maybe I misunderstand a thing here?
>
>
>>
>> Presumably I call something like project.getPlugin(key).getDependencies()?
>>
>> If the 'key' required for project.getPlugin(key) is of the form 
>> myGroup:myPlugin:version e.g. com.megacorp:thing-plugin:1.0.2
>>
>> can I get my mojo's own key programmatically in the mojo to avoid hard-coding 
>> it?
>
>
> Can you please explain what you are trying to accomplish ?

The users of my plugin define a dependency which the mojo unpacks and extracts 
certain files from.

At the moment, I have coded the plugin to take the groupId and artifactId of 
this dependency via the mojo config.

This strikes me as doppel gemoppelt for the user to put that info in twice. I 
thought I could just enter it once as a plugin dependency in the user project 
pom - assuming it would be the only one.

Regards
Adam

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