PluginVersionResolutionException in Maven project when I set packaging to bundle - maven

In my Maven project when I change the packaging type from 'jar' to 'bundle' most of my plugins (compiler, deploy, install, resources, surefire) lose their versions. Why is this?
My pom.xml is below:
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.ui_4.4.35_patch</artifactId>
<version>1.0.0</version>
<packaging>bundle</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>4.2.1</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Export-Package>web.admin.*</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>

There are two possible approaches. The one I use for my own projects is to keep the bundle packaging and add the maven plugin versions to a pluginManagement section in the pom.xml. For example:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
<!-- Add you current 'plugins' section here. -->
</build>
In addition to the version, you can also add configuration to each plugin. If your project has a parent pom, it would be natural to add the pluginManagement section there instead of in your bundle module.
Alternatively, as suggested by #khmarbaise, you can use jar packaging and just use the maven-bundle-plugin to generate the manifest. That approach is described in the plugin documentation page.

Related

SpotBugs site report inconsistent with spotbugs:gui goal

I have set up SpotBugs to help us adhere to some standards, but I get different results in my generated site compared to SpotBugs user interface. This is my configuration of SpotBugs in my pom file:
<build>
<plugins>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs-maven-plugin.version}</version>
<configuration>
<excludeFilterFile>
src/test/resources/SpotBugsExcludeFilter.xml
</excludeFilterFile>
</configuration>
<dependencies>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs</artifactId>
<version>${spotbugs.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
...
<reporting>
<plugins>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs-maven-plugin.version}</version>
<configuration>
<excludeFilterFile>
src/test/resources/SpotBugsExcludeFilter.xml
</excludeFilterFile>
</configuration>
</plugin>
</plugins>
</reporting>
When I run mvn clean install site, the site reports 5 bugs.
When I run mvn clean install spotbugs:gui, the gui reports 0 bugs.
How come there is a difference? It seems as if the site goal disregards my exclusion filter, but I can't see why. I am also not entirely sure how the build/plugins section correlates with the reporting/plugins section. If someone could tell me what I'm messing up here I'd be very grateful.
spotbugs:gui is not triggering the reporting scope where your configuration is defined.
You should be specifying your SpotBugs configuration in the <build> section.
<build>
<plugins>
[...]
<!-- SpotBugs Static Analysis -->
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs-maven-plugin.version}</version>
<configuration>
<excludeFilterFile>src/test/resources/SpotBugsExcludeFilter.xml</excludeFilterFile>
</configuration>
</plugin>
</plugins>
</build>
https://github.com/find-sec-bugs/find-sec-bugs/wiki/Maven-configuration

RED5. Maven deploy issue

I am trying to publish an spring mvc application in Red5Pro server. (tomcat).
I use Maven as build tool, but it seems to not work properly, because the
compiled classes are not found in WEB-INF/classes. This is my project structure:
The project is found in RED5ProHome/webapps, but without the compiled classes. (only xml, jsp and html).
This is my pom.xml
<modelVersion>4.0.0</modelVersion>
<groupId>org.red5.example</groupId>
<artifactId>springmvc</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<build>
<finalName>springmvc</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
<dependencies>
// all dependencies needed
</dependencies>
Another point is that I export my project as war, manually, it works.
Do you have any idea how can I solve this issue?
Thank you.

Difference between plugins in project->build->pluginManagement and project->build

A snippet of my pom looks something like:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>1.0-alpha-7</version>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.5</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<configuration>
<updateDependencies>true</updateDependencies>
<generateBackupPoms>false</generateBackupPoms>
</configuration>
</plugin>
</plugins>
</build>
Can anybody explain the difference between the <plugins> listing under project->build->pluginManagement and project->build>?
From the POM documentation at http://maven.apache.org/pom.html
pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way,
except that rather than configuring plugin information for this
particular project build, it is intended to configure project builds
that inherit from this one. However, this only configures plugins that
are actually referenced within the plugins element in the children.
The children have every right to override pluginManagement
definitions.

maven-war-plugin always running even without child pom.xml reference...why?

I am specifying:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<outputDirectory>C:\apache-tomcat-7.0.42\webapps</outputDirectory>
</configuration>
</plugin>
.
.
.
However, even though I do not specify anything in the respective children pom.xml, the war file is still being moved to that output directory.
As far as I know, pluginManagement is only there for reference from the children pom right?
Thank you for your help
By default Maven will invoke the maven-war-plugin war:war goal as part of the package phase if you specify <packaging>war</packaging> in your pom.xml
Since you have a <pluginManagement> stanza for maven-war-plugin specifying a custom <outputDirectory> in your parent pom.xml your child pom.xml will use this property when you run the package phase.
http://maven.apache.org/plugins/maven-war-plugin/usage.html

How to Deploy only the sub-modules using maven deploy?

How do i deploy only the sub-modules of the project?
i have a project as;
ProjectA
- Submodule B
- Submodlue C
- Submodule D
The submodules are packaged as jar and is deployed to maven repo.how can only the sub -modules be deployed to the maven repository and not the main project?
Put this in module(s)(or module's pom.xml) that you don't want to deploy:
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
Since this is inherited by submodules, you have to put this in submodules that you do want to deploy:
<properties>
<maven.deploy.skip>false</maven.deploy.skip>
</properties>
Another suggestion could be doing the following:
mvn deploy -pl SubModuleB
This worked for me. Similar to other answer except added missing plugins element. Add to parent POM.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.4</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
You can use the technique described in my blog.
In this case, you'd disable default-deploy (or what the name is) in the root pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>default-deploy</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
And then enable it for submodules:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
</execution>
</executions>
</plugin>
This is working on my side
Put the plugin declaration in the parent pom , skip=true, but set inherited=false.
This prevents from repeating the on each child modules.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip>
</configuration>
<inherited>false</inherited>
</plugin>
You can configure the maven-deploy-plugin in the POM of a module to exclude it from the deploy:
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.4</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
...
</build>

Resources