maven jar plugin cannot be resolved - java

I am trying to learn hyperjaxb3, so I downloaded the zip file containing the maven project for the purchase order tutorial for hibernate and maven from this link, and then imported it into eclipse as a new maven project. But I am getting the following error message in the pom.xml:
Plugin execution not covered by lifecycle configuration:
org.jvnet.hyperjaxb3:maven-hyperjaxb3-plugin:0.5.6:generate (execution: default, phase: generate-sources)
I tried to resolve this error message by adding the following dependency to the pom.xml, which I found at this link:
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
</dependency>
But I am still getting the same error. There is no stack trace because I have not tried to compile the program. It is a compile error message that eclipse gives in the pom.
How can I resolve this error?
The complete pom.xml can be viewed by clicking on this link.

Plugins with executions goals need to be moved to <pluginManagement> to get rid of this error. It should look like this:
<build>
<plugins>
<!-- plugins -->
</plugins>
<pluginManagement>
<plugins>
<!-- plugins with execution goals -->
</plugins>
</pluginManagement>
</build>

Related

Use JAXB with plexus-compiler-eclipse plugin in maven profile

I am working on a project where we want to use the plexus-compiler-eclipse plugin during a Jenkins pipeline to check for increases in the number of warnings generated by the Eclipse compiler. We still want to use the javac compiler for the normal build and test stage, so I am trying to create a maven profile we can run during the warnings stage that utilizes the Eclipse compiler.
When I run the Eclipse compiler over our code, I get a compile error about JAXB dependencies being missing. I know this is due to our move to Java 11 from Java 1.8, but we do not get this error when building with the javac compiler. I have tried adding the jakarta.xml.bind-api dependency to the maven-compiler-plugin, but this does not help, nor does adding the org.glassfish.jaxb dependency or the javax.xml.bind:jaxb-api dependency.
I cannot share the full pom because this project is proprietary, but the profile I'm building looks like this:
<profile>
<id>eclipse-compile</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1></version>
<configuration>
<compilerId>eclipse</compilerId>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArguments>
<properties>${project.basedir}/.settings/org.eclipse.jdt.core.prefs</properties>
</compilerArguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>ecj</artifactId>
<version>3.25.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
I was putting the various JAXB dependencies I tried in the <dependencies> section under the org.eclipse.jdt entry.
Anyone else encounter this or know what to do about it?
The issue stemmed from the Maven build running in Java 11 but our normal compile stage forking to a Java 1.8 executable. Because the Plexus compiler cannot fork to a new environment, there was not a way for it to access the Java EE dependencies. We just need to update our entire project to be compatible with Java 11 at compile-time.

Can run spring boot application from eclipse but not from terminal

I have a problem with a Spring boot project, it has another spring boot project as a dependency in its pom.xml.
I can run it properly using eclipse, but an error shows up when I try to run it with terminal using the command mvn spring-boot:run.
[ERROR] Failed to execute goal on project platform-service: Could not resolve dependencies for project com.test.platform:platform-service:jar:0.0.1-SNAPSHOT: Could not find artifact com.test:student-service:jar:exec:0.0.1-SNAPSHOT
This is how I added the dependency in pom.xml :
<dependency>
<groupId>com.test</groupId>
<artifactId>student-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
I have tried different solutions like mvn package spring-boot:repackage but it didn't work.
Thank you so much.
Add this plugin after dependencies in pom.xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Save this and run again.

Maven dependency directory not created in target

I'm using Maven 3.3.3 to create a Spring MVC application that can be deployed to Heroku. I intend to use jetty-runner as suggested by the Heroku documentation (https://devcenter.heroku.com/articles/getting-started-with-spring-mvc-hibernate).
I can't get Maven to create the target/dependency folder in which to copy the jetty-runner.jar file. I use the commands:
mvn clean
mvn package
I get the target directory created, with all resources, web pages and source, but not the "target/dependency" folder where the jetty-runner.jar file should be copied.
My pom.xml is almost identical to the one provided by the sample application in the link above. My project and pom.xml file can be found in the following GitHub repository:
https://github.com/gfigueroa/nlp-tools-spring-heroku
Add an activation of your dependency-plugin outside the <pluginManagement> section:
...
<build>
<pluginManagement>
<plugins>
<!-- Leave as is -->
...
</plugins>
</pluginManagement>
<!-- Add the section below -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
</plugins>
</build>
...
The <pluginManagement> section is for declaring how your plugins should behave when activated. The activation itself is done outside this section.

Maven PMD plug-in not generating a report with 'mvn site' command or 'pmd:pmd'

I am reading an interesting tutorial here: http://www.avajava.com/tutorials/lessons/how-do-i-generate-pmd-and-cpd-reports-for-a-site.html?page=1
This tutorial shows how to use Maven to run the open-source static-analysis tool, PMD, and to see the generated output on a Maven created website. Maven can easily create websites with mvn site command, but this tutorial shows how to use PMD for more helpful metrics on the source code.
The instructions were followed to the best of my ability. Here is my pom.xml file that came from reading the tutorial:
<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>com.name.bookstore</groupId>
<artifactId>bookstore</artifactId>
<packaging>jar</packaging>
<version>1</version>
<name>bookstore</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<extensions>
<!-- start for deploying using webdav -->
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav</artifactId>
<version>1.0-beta-2</version>
</extension>
</extensions>
</build>
<distributionManagement>
<!-- start -location where site is deployed -->
<site>
<id>site.deployments</id>
<name>Site deployments</name>
<url>dav:localhost/${basedir}</url>
</site>
</distributionManagement>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.1</version>
</plugin>
</plugins>
</reporting>
</project>
When I run the command: mvn clean site I get a website built by Maven with a bunch of different pages but none of them show anything in regards to PMD. What am I missing here? Why am I not seeing anything in regards to PMD in the generated website?
Also, when I run mvn pmd:pmd there is a successful build but I do not obtain any helpful PMD metrics. I even coded in some unused variables and methods in one of my Java source files as illustrated in the above linked tutorial and there is no helpful output.
The mvn pmd:pmd command does appear to create some files though. A couple are files of rules for the engine it looks like and the others are empty. Please see the screen-shots of this below:
Figure 1: Files created by pmd:pmd command
Figure 2: Empty pmd file - even though there are obvious errors in Java source file
Does anyone out there know what is up? Why is PMD not working with Maven for me?
Thanks for reading this.
Also, from what I have read around the Internet on PMD's website and Maven's website there should be some information in the "Project Reports" section. There is no data here though from PMD. Please see the below screen-shot.
Figure 3: No PMD Data found in Project Reports
Regards
UPDATE
When I change the PMD section of the pom.xml file to the below snippet I obtain some CPD results via PMD but still nothing from PMD on code bugs. I even coded in an NullPointerException and PMD said nothing even when issuing the mvn pmd:check command.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.4</version>
<configuration>
<linkXref>true</linkXref>
<sourceEncoding>utf-8</sourceEncoding>
<minimumTokens>1</minimumTokens>
<targetJdk>1.7</targetJdk>
</configuration>
</plugin>
In the snippet I changed the sourceEncoding tag to be utf-8 because everything I see in regards to this is utf-8. I also changed the minimumTokens value to 1 to try to get more output from this plug-in. I also put this snippet in the <build> section to try and get results but still nothing... :/
Thanks for studying this...
The maven-pmd-plugin by default skips nowadays empty reports (property skipEmptyReport). You'll need to set this to false, to get in your site always a PMD/CPD report:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.4</version>
<configuration>
<skipEmptyReport>false</skipEmptyReport>
</configuration>
</plugin>
</plugins>
</reporting>
This applies for both PMD and CPD. I assume, this is your problem, as in Figure 2, you show, there are no PMD violations detected (pmd.xml file is empty).
The property minimumTokens configures CPD and defines how long a code snipped at a minimum must be to be declared as a duplicate. The lower the number, the more duplicates are detected, but the duplicates can also be much shorter and therefore maybe more often false positives.
Without further configuring maven-pmd-plugin it uses by default these three PMD rulesets: java-basic, java-imports, java-unusedcode. See also property rulesets. If you want to detect specific problems, then you'll need to enable these rules. See also How to make a ruleset.

Eclipse Kepler Project Configuration

Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-resources-plugin:2.5:resources (execution: default-resources, phase: process-resources) pom.xml /Project line 1 Maven Project Build Lifecycle Mapping Problem
Here is the POM.xml
<project xmlns="maven.apache.org/POM/4.0.0"; xmlns:xsi="w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="maven.apache.org/POM/4.0.0 maven.apache.org/xsd/maven-4.0.0.xsd">; <modelVersion>4.0.0</modelVersion>
<groupId>Assignment</groupId>
<artifactId>ApsalarAssignment</artifactId>
<version>0.0.1-SNAPSHOT</version>
</project>
I am getting this error on Kepler, Eclipse while making a new Maven Project. Don't know how to figure it out as I am new to Maven as well as Eclipse. Any help would be highly appreciated.
This problem is due to missing <pluginManagement> tag in pom.xml
In order to fix this error in eclipse, you need to <pluginManagement> tag around your <plugins> tag, like shown below.
<build>
<pluginManagement>
<plugins>
<plugin> ... </plugin>
<plugin> ... </plugin>
....
</plugins>
</pluginManagement>
</build>
As per Maven documentation
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.
Shishir

Categories