Maven + Custom Type/Packaging

Answered

Hello,
There is something  i dont undersand with the maven plugin :
I'm working on a Maven project with custom packaging and we have a maven plugin who handle it.

The maven plugin plexus configuration (/META-INF/plexus/components.xml) :

<?xml version="1.0" encoding="UTF-8"?>
<component-set>
    <components>
        <component>
            <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
            <role-hint>the-type</role-hint>
            <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
            <configuration>
                <phases>
                    ...
                </phases>
            </configuration>
        </component>
        <component>
            <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
            <role-hint>the-type</role-hint>
            <implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
            <configuration>
                <type>the-type</type>
                <extension>jar</extension>
                <language>java</language>
                <addedToClasspath>true</addedToClasspath>
            </configuration>
        </component>
        </components>
</component-set>

Here the declaration of the plugin in the pom project :

<plugin>
    <groupId>the.group.id</groupId>
    <artifactId>the.artifact.id</artifactId>
    <extensions>true</extensions>
    <executions>
        <execution>
            <goals>
                <goal>inplace</goal>
            </goals>
        </execution>
    </executions>
</plugin>

And for the specifics dependencies we have :

<dependency>
    <groupId>groudId</groupId>
    <artifactId>artifactId</artifactId>
   <version>xxx.xx.xx</version>
   <type>the-type</type>
</dependency>

When i import the project, the dependency with custom type are not resolved, because intellij dont know the custom type.
So i looked into the sources of the maven plugin, and i deduced that i had to make a plugin who extends MavenImporter for handling my custom type.

Something like :

<idea-plugin version="2">
    <name>xxxx</name>
    <id>xxx</id>
    <description>
       xxx
    </description>
    <version>x.x.x</version>
    <vendor>xxx</vendor>
    <depends>org.jetbrains.idea.maven</depends>
    <extensions defaultExtensionNs="org.jetbrains">
        <idea.maven.importer implementation="custom.MyImporter"/>
    </extensions>
</idea-plugin>

In the MyImporter constructor, i'm passing the groupId and the artifactId of our plugin and i override the getSupportedPackagings, getSupportedDependencyTypes, isApplicable methods (like in the Android plugin).

When i import the project, my plugin is correctly used but intellij fail to download the artifact because it dont use the ArtifactHandler declared in the plugin.

On the, MavenModelConverter or Maven2ModelConverter, convertExtension method the ArtifactHandler is alway null.
ArtifactHandler handler = artifact.getArtifactHandler(); <--- is alway null
So intellij try to download artifactId.the-type and not artifactId.jar (who doesnt exist in the repository).

I dont know if my approach is correct or not and what am i doing wrong .....


ps: sorry for my poor english

12 comments

Is this the expected behavior or this is a bug ?

0

It's a bug, but I have no idea how to fix it in the near future. May be IDEA should execute "mvn dependency:resolve" when user press "Download sources".

0

Hello, thank you for your answer !

There is something that bothering me, the artifacts are resoled by type in the intellij idea plugin.
But with the artifact handler stuff it would not be better to handle the artifacts the extention ?

0

Is there a workaround for this issue ?

I couldn't find a way to use maven artifacts with a custom packaging that add jars to the classpath.

Jon

1
Hello, 
I work on an open source JEE framework called Lutece, used to build a lot of website owned by the  Cityof Paris. Here is the github of this framework : https://github.com/lutece-platform
I was recently curious to try Intellij IDEA to work on our projects, but i'have encounter a major issue about the way that Intellij add the resolved Maven dependencies to the project classpath. 
In our project, we use custom maven package (called, for example "lutece-plugin") in our pom.xml; because we have defined custom Maven goals that use those maven custom package to perform various actions. Here is an example of a dependency in our pom : 
 
<dependency>
            <groupId>fr.paris.lutece.plugins</groupId>
            <artifactId>plugin-workflow</artifactId>
            <version>[4.3.4,)</version>
            <type>lutece-plugin</type>
</dependency>
 
With the default settings of Intellij IDEA; when i run a build on the project which have for example, this dependency, with an external Maven; Maven can't resolve dependencies. In the settings of Maven, in Intellij, i had to add "lutece-plugin" in the handled custom Maven type types. 
But even with that, the dependencies are correctly resolved, but they are not correctly added to the classpath of the project, and the method calls, the classes apper as "Not found error". 
 Here is for example a simple maven-based project to reproduce the problem : 
. The maven custom goal we use to build this project is "lutece:exploded" ; but a classic maven goal for building with dependency is causing trouble too. 
 
May you help me to use resolve this issue, to allow us to use your IDE ? 
 
Alexandre
0

Alexandre,

Looks like there are issues with plugin version. Does it builds fine from command line?

 

0

Hello,

Thank you for your answer,

Actually, all our components are building correctly from mvn command line. The dependencies resolving is fine, when the building is launched from mvn command line, or from embedded maven in several IDE, such as Netbeans or Eclipse. The issue appears only in Intellij, when we use the Maven plugin of the IDE.

Here are examples of our components causing troubles in IntelliJ :

https://github.com/lutece-platform/lutece-core
https://github.com/lutece-platform/lutece-cms-plugin-htmlpage
https://github.com/lutece-platform/lutece-dev-plugin-example/tree/develop

Here is an example of our custom package declaration :

<!--
The artifact handler for Lutece plugin components.
-->
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>lutece-plugin</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<extension>jar</extension>
<type>lutece-plugin</type>
<language>java</language>
<addedToClasspath>true</addedToClasspath>
<includesDependencies>false</includesDependencies>
</configuration>

</component>

This example can be found in https://github.com/lutece-platform/tools-maven-lutece-plugin/blob/master/src/main/resources/META-INF/plexus/components.xml

This kind of declaration is authorized in the Maven spec; and it allows to set the dependancy file extension to download from the repositories during the building step, in the <extension> tag. This kind of declaration seem to be not correctly handled by IntelliJ. The files are downloaded as "dependance.lutece-plugin" instead of "dependance.jar"; and the link between custom package and dependency extension is not correctly set.

This issue seems to be exactly the same that the author of this topic and Jon Harper had encounter


May you help me to fix this issue or find a workaround?

Thank you very much,

Regards,
Alexandre

0

Seems we have similar issue on YouTrack: https://youtrack.jetbrains.com/issue/IDEA-170272. I'll ask developer for any workaround.

0

Hello,

Yes, thats exactly the same issue.

Thank you for your answer;

0

Hello,

Do you have some news about this issue? Did you find any workaround or fix? We can't still use Intelligy in City of Paris projects.

Regards

Alexandre CLOSE

0

The request is till open. Considering it has got only one vote in a year, it's priority is lower than many other issues in YouTrack.

0

Please sign in to leave a comment.