Maven: `Unknown packaging: bundle` error from a dependency packaging as bundle - java

I am running mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.1:copy-dependencies in my project, and I'm seeing the following errors:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:3.1.1:copy-dependencies (default-cli) on project beam-sdks-java-core: Some problems were encountered while processing the POMs:
[ERROR] [ERROR] Unknown packaging: bundle # line 6, column 16: 1 problem was encountered while building the effective model for org.xerial.snappy:snappy-java:1.1.4
[ERROR] [ERROR] Unknown packaging: bundle # line 6, column 16
Looking at Snappy's pom file, it looks like so:
<?xml version='1.0' encoding='UTF-8'?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
<packaging>bundle</packaging>
<description>snappy-java: A fast compression/decompression library</description>
<version>1.1.4</version>
<name>snappy-java</name>
....
Specifically, the <packaging>bundle</packaging> line seems to be the problem.
I tried adding the maven-bundle-plugin to my own POM file's <build> tag, but that won't fix it (and why should it? I'd think that a dependency's config shouldn't affect my pom?)
How do I enable the maven-bundle-plugin for my dependencies? Do I need to add it to a specific subsection of my pom that refers to apache.maven.plugins:maven-dependency-plugin:3.1.1:copy-dependencies?
Also, for extra info, my Maven version is 3.5.0

I tried adding the maven-bundle-plugin to my own POM file's
tag, but that won't fix it (and why should it? I'd think that a
dependency's config shouldn't affect my pom?
And you are right : it is not the maven-bundle-plugin as a dependency that you need to
add to make the bundle package usable in your build.
What you need is adding the maven-bundle-plugin as a plugin to
enhance the default Maven lifecycle such as :
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Include-Resource>
....
</Include-Resource>
</instructions>
</configuration>
</plugin>
</plugins>
<build>
You can find the information in the apache-felix-maven-bundle-plugin.

This is actually an issue with snappy-java 1.1.4. Their pom does not include the bundle plugin. However, version 1.1.7 switches to jar packaging.
You can work around this by using maven-dependency-plugin 2.10.

Related

Maven can not calculate build path in Eclipse

I am very new to using Maven, and I'm trying to follow along with an online tutorial using Eclipse, however when I'm writing the Maven file, I get the following Error:
CoreException: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.8.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-compiler-plugin:jar:3.8.1: ArtifactResolutionException: Failure to transfer org.apache.maven.plugins:maven-compiler-plugin:pom:3.8.1 from http://repo1.maven.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven.plugins:maven-compiler-plugin:pom:3.8.1 from/to central (http://repo1.maven.org/maven2): Failed to transfer http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.8.1/maven-compiler-plugin-3.8.1.pom. Error code 501, HTTPS Required
My pom.xml looks like this, and the plugin tag is underlined with a red error
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pluralsight</groupId>
<artifactId>conference</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
I've tried deleting the repository folder in my .m2 folder, and updating my project, but I haven't found any fix yet. Can someone help me out?
Your Maven versions is probably out of date.
Newer versions should automatically go to the central maven repo using HTTPS.
Your error is saying: Error code 501, HTTPS Required
When trying to go to the central repo.
Update maven to the latest version or atleast to 3.2.3.
Download the latest Maven version from: https://maven.apache.org/download.cgi
In Eclipse you can change the maven version like this:
Preferences -> Maven -> Installations -> Add...
Now select the Maven you just installated

Maven multi-module + inheritance: Issue in building submodules when maintaining parent version number via placeholders

This is rather a follow-up for this answer on maintaining parent version numbers via placeholders:
I am on Maven 3.6.1, and have the following multi-module Maven project structure:
pom.xml
a/
pom.xml
b/
pom.xml
pom.xml (parent):
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tuna</groupId>
<artifactId>root</artifactId>
<version>${ver}</version>
<packaging>pom</packaging>
<modules>
<module>a</module>
<module>b</module>
</modules>
<properties>
<ver>1.0-SNAPSHOT</ver>
</properties>
</project>
a/pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.tuna</groupId>
<artifactId>root</artifactId>
<version>${ver}</version>
<relativePath>..</relativePath>
</parent>
<artifactId>a</artifactId>
<version>${ver}</version>
</project>
b/pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.tuna</groupId>
<artifactId>root</artifactId>
<version>${ver}</version>
<relativePath>..</relativePath>
</parent>
<artifactId>b</artifactId>
<version>${ver}</version>
<dependencies>
<dependency>
<groupId>com.tuna</groupId>
<artifactId>a</artifactId>
<version>${ver}</version>
</dependency>
</dependencies>
</project>
Note that b depends on a.
Now, when I build this with
mvn clean install
it gets built successfully (with some 'version' contains an expression but should be a constant warnings - fair enough).
However, if I do
mvn clean install -rf :b
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.tuna:a:jar:1.0-SNAPSHOT
[WARNING] 'version' contains an expression but should be a constant. # com.tuna:a:${ver}, C:\Users\janaka\code\dustbin\mvn-multi-module\a\pom.xml, line 15, column 14
[WARNING] 'version' contains an expression but should be a constant. # com.tuna:root:${ver}, C:\Users\janaka\code\dustbin\mvn-multi-module\pom.xml, line 9, column 14
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.tuna:b:jar:1.0-SNAPSHOT
[WARNING] 'version' contains an expression but should be a constant. # com.tuna:b:${ver}, C:\Users\janaka\code\dustbin\mvn-multi-module\b\pom.xml, line 15, column 14
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.tuna:root:pom:1.0-SNAPSHOT
[WARNING] 'version' contains an expression but should be a constant. # com.tuna:root:${ver}, C:\Users\janaka\code\dustbin\mvn-multi-module\pom.xml, line 9, column 14
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] -----------------------------< com.tuna:b >-----------------------------
[INFO] Building b 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.472 s
[INFO] Finished at: 2019-10-09T00:08:14+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project b: Could not resolve dependencies for project com.tuna:b:jar:1.0-SNAPSHOT: Failed to collect dependencies at com.tuna:a:jar:1.0-SNAPSHOT: Failed to read artifact descriptor for com.tuna:a:jar:1.0-SNAPSHOT: Cannot access central (https://repo.maven.apache.org/maven2) in offline mode and the artifact com.tuna:root:pom:${ver} has not been downloaded from it before. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
The same happens if I run mvn clean install from within b/.
Apparently Maven can resolve ${ver} for both b and a, but when it scans a's POM it fails to resolve a's parent's ${ver} version (although the relativePath entry is there); probably because Maven is reading a's POM from the local repository (~/.m2/repository/ - where the relative path won't make sense) and not from the local codebase?
Is there a way to get this to work - avoid the error and get partial builds working - maybe via some hack; like passing a default value for ${ver} via a system property?
P.S.:
Yeah yeah, I know it's all smelly and evil to use placeholders in parent version number; but my actual project has around 30 modules, many of which are inter-dependent on others. So I just want a way to maintain a single version number (one line) which I can change easily - without having to change and commit a couple hundred lines every time I upgrade.
Basically I'm not asking for suggestions to replicate the version number all over the place instead (and use something like Maven versions plugin to upgrade them all at once) - I just need a hack to get the current structure working.
(So I believe this cannot be flagged as a duplicate - because replication and placeholders are the only two options I came across in SO, and my question is about a specific case of the latter. 🙏)
If it is only to maintain a single version across the whole project then you can use revision placeholder.
The parent must declare it and children can inherit it.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tuna</groupId>
<artifactId>root</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<modules>
<module>a</module>
<module>b</module>
</modules>
<properties>
<revision>1.0-SNAPSHOT</revision>
</properties>
</project>
And your a/pom.xml do not need to declare the placeholder property again. You just use parent revision.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.tuna</groupId>
<artifactId>root</artifactId>
<version>${revision}</version>
<relativePath>..</relativePath>
</parent>
<artifactId>a</artifactId>
</project>
Read more at https://maven.apache.org/maven-ci-friendly.html#Multi_Module_Setup
Just mentioning my final workaround, in case it helps someone:
I ended up overriding the maven-resources-plugin execution to make a copy of each POM, replacing all placeholders (config added to root POM so that it applies to all submodules):
<!-- replaces version number placeholders in POMs, with current values -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration combine.children="append">
<resources>
<resource>
<directory>.</directory>
<include>pom.xml</include>
<filtering>true</filtering>
</resource>
</resources>
<outputDirectory>target</outputDirectory>
</configuration>
</execution>
</plugin>
I also override maven-install-plugin to use/install this modified (fixed) copy from target/, instead of the original with placeholders:
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<configuration combine.children="append">
<pomFile>target/pom.xml</pomFile>
</configuration>
</plugin>
Now the POMs installed to local/remote repos are free from placeholders; so any dependent project/module would be able to process those POMs successfully! In a sense I believe this is the right approach, because in my case the placeholders are only there for the developer's convenience; and there is actually no reliable way to resolve their values once they are installed into a Maven repo.
One downside is that all placeholders get resolved; e.g. if a POM contained a ${java.home} expression, the installed copy now contains the actual absolute path to the builder machine's Java installation. I still did not find a proper way to exclude such (a subset of) placeholders from being replaced.

installing a jar with maven-install-plugin to local repo creates pom without dependencies [duplicate]

I have a maven plugin, which I have not uploaded to the central repository, but which I want to use in my projects.
What works
I can install the maven plugin like this:
git clone https://github.com/RudolfVonKrugstein/jinja-maven-plugin.git
cd jinja-maven-plugin
mvn install
Then I can use the plugin like this pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>de.wintercloud</groupId>
<artifactId>sample</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>de.wintercloud</groupId>
<artifactId>jinja-maven-plugin</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>de.wintercloud</groupId>
<artifactId>jinja-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>renderjinja</goal>
</goals>
</execution>
</executions>
<configuration>
<outputFile>out.txt</outputFile>
<templateFile>templ.jinja</templateFile>
<varFile>vars.yaml</varFile>
</configuration>
</plugin>
</plugins>
</build>
</project>
Here are the other files relevant to the compile:
templ.jinja:
{{ Name }}
vars.yaml:
Name: MyWonderfullName
This works:
> mvn compile
> cat out.txt
MyName
Nice!
What does not work
Now I am trying to give the plugin as a jar to my colleagues so that they can simple install the jar. The Idea is to do it like this:
git clone https://github.com/RudolfVonKrugstein/jinja-maven-plugin.git
cd jinja-maven-plugin
mvn package
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=target/jinja-maven-plugin-1.0.jar
When I now do (in the sample project dir)
mvn compile
I get this error:
[ERROR] Failed to execute goal de.wintercloud:jinja-maven-plugin:1.0:renderjinja (default) on project sample: Execution default of goal de.wintercloud:jinja-maven-plugin:1.0:renderjinja failed: A required class was missing while executing de.wintercloud:jinja-maven-plugin:1.0:renderjinja: org/yaml/snakeyaml/Yaml
How can I install the jar so that I can use it as a plugin?
It looks to me as if dependencies are missing. Why?
You just hit MINSTALL-110, which is going to be fixed in the next 3.0.0 release of the Maven Install Plugin. The core issue here is that you're installing manually a JAR file with the file parameter, the plugin detects that there is a POM inside, but only keeps the coordinate information (group id, artifact id, packaging and version), not the whole POM. As such, when the POM is installed, the dependencies aren't kept.
Indeed, if you take a look at the installed POM, you will see
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>de.wintercloud</groupId>
<artifactId>jinja-maven-plugin</artifactId>
<version>1.0</version>
<packaging>maven-plugin</packaging>
<description>POM was created from install:install-file</description>
</project>
which shows that the dependencies weren't retained. And if you take a look at the Maven logs in debug mode when running the install-file command, it will show
[DEBUG] Using META-INF/maven/de.wintercloud/jinja-maven-plugin/pom.xml for groupId, artifactId, packaging and version
A work-around waiting for version 3.0.0 is to specify the path to the POM file to install, along with the main artifact, by specifying the pomFile parameter. Run the following instead:
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=target/jinja-maven-plugin-1.0.jar -DpomFile=pom.xml
Then the full POM will be installed, not a generic stub.
With this change, the error
[ERROR] Failed to execute goal de.wintercloud:jinja-maven-plugin:1.0:renderjinja (default) on project sample: Execution default of goal de.wintercloud:jinja-maven-plugin:1.0:renderjinja failed: A required class was missing while executing de.wintercloud:jinja-maven-plugin:1.0:renderjinja: org/yaml/snakeyaml/Yaml
will not happen anymore. Maven will correctly download the dependencies and use them for the plugin.

Maven : Migrating Android project from Ant to Maven

I started an Android project, and by default it is built with ANT, I am trying to upgrade it to Maven so I can get rid of compile time problems I am having with Android SDK, and ease of library import and management. The problems I have encountered are :
1) How to modify build.xml to instruct it to use maven.
2) Maven complaining folder structure is wrong.
Here is my build.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project name="myapp" default="help">
<property file="local.properties"/>
<property file="ant.properties"/>
<property environment="env"/>
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME"/>
</condition>
// and more
So I presume I have to modify the ant.properties attribute, how can I suggest to use Maven??
Here is the POM.xml I have pasted in the Parent directory of the project, but when I try to run mvn compile, I get the following error :
Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:4.0.0-rc.2:generate-sources (default-generate-sources) on project gs-maven-android:
[ERROR]
[ERROR] Found files or folders in non-standard locations in the project!
[ERROR] ....This might be a side-effect of a migration to Android Maven Plugin 4+.
[ERROR] ....Please observe the warnings for specific files and folders above.
[ERROR] ....Ideally you should restructure your project.
[ERROR] ....Alternatively add explicit configuration overrides for files or folders.
[ERROR] ....Finally you could set failOnNonStandardStructure to false, potentially resulting in other failures.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
And finally, here is the POM.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.hello</groupId>
<artifactId>MyAPP</artifactId>
<version>1.0</version>
<packaging>apk</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.1.1.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>4.0.0-rc.2</version>
<configuration>
<sdk>
<platform>20</platform>
</sdk>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
So what am I doing wrong here? Any help would be nice. I am using Intellij Idea on Ubuntu Linux. Thanks.
Please update to a full release version and then update the error message in the post. The latest release is 4.3.0.
The warning is about the source code and other sources being located in non-standard folders. You should use the standard structure. The full version will show error message with details where everything should be.

How do I create a new packaging type for Maven?

I have a requirement to create jar files with Maven, but they need to be installed to the repository with a "foobar" extension , and it would be nice if they could have their own packaging type so we can identify those artifacts by the packaging.
Can I set up a new packaging type to do this?
To do as you described, create a Maven project with packaging jar (as stated here, as there won't be mojo definitions). In the src/main/resources/META-INF/plexus sub-folder create a components.xml with the following contents (assuming you want the packaging type to be "my-custom-type", change it to "foobar" if you wish).
<component-set>
<components>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>my-custom-type</role-hint>
<implementation>
org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping
</implementation>
<configuration>
<phases>
<!--use the basic jar lifecycle bindings, add additional
executions in here if you want anything extra to be run-->
<process-resources>
org.apache.maven.plugins:maven-resources-plugin:resources
</process-resources>
<package>
org.apache.maven.plugins:maven-jar-plugin:jar
</package>
<install>
org.apache.maven.plugins:maven-install-plugin:install
</install>
<deploy>
org.apache.maven.plugins:maven-deploy-plugin:deploy
</deploy>
</phases>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>my-custom-type</role-hint>
<implementation>
org.apache.maven.artifact.handler.DefaultArtifactHandler
</implementation>
<configuration>
<!--the extension used by Maven in the repository-->
<extension>foobar</extension>
<!--the type used when specifying dependencies etc.-->
<type>my-custom-type</type>
<!--the packaging used when declaring an implementation of
the packaging-->
<packaging>my-custom-type</packaging>
</configuration>
</component>
</components>
</component-set>
Then in a pom that is to have the custom packaging, declare the required type in the packaging element, and ensure you have specified the plugin so the custom packaging can be contributed. Declaring <extensions>true</extensions> tells Maven that the plugin contributes packaging and/or type handlers to Maven.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>name.seller.rich</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>my-custom-type</packaging>
<build>
<plugins>
<plugin>
<groupId>name.seller.rich.maven.plugins</groupId>
<artifactId>maven-foobar-plugin</artifactId>
<version>0.0.1</version>
<!--declare that this plugin contributes the component extensions-->
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
When the project is packaged, it will be a jar, with a .jar extension, however when it is installed/deployed, Maven will deliver the file to the repository with the ".foobar" extension as specified in components.xml
Following up on Rich Seller's original answer:
If as he recommends you use a packaging type jar then most likely in the project where you reference your plugin you'll receive:
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] The plugin descriptor for the plugin Plugin [com.ocado.mvn.packaging:Jar-Gem] was not found. Please verify that the plugin JAR /home/ndb/.m2/repository/com/ocado/mvn/packaging/Jar-Gem/1.0.0/Jar-Gem-1.0.0.jar is intact.
This is because no plugin descriptor exists in the JAR you generated.
You can use the following to bypass the No mojo definitions.. error he mentions:
<packaging>maven-plugin</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.1</version>
<configuration>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
</plugin>
</plugins>
</build>
This configuration was found in plugin docs example here.
The maven-plugin packaging type lifecycle has the plugin:descriptor goal bound to generate-resources phase. This is specified in Sonatype's official documentation.

Categories

Resources