I am attempting to learn maven on a small project of my own, using eclipse. I converted the existing project to the maven standard directory configuration, and it was building; now I'm trying to get maven to produce the jar for the application. The following is pom.xml:
<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.rc </groupId>
<artifactId> SpaceCheck </artifactId>
<version> 0.9.1-SNAPSHOT </version>
<name> SpaceCheck </name>
<packaging> jar </packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId> org.apache.maven.plugins </groupId>
<artifactId>maven-jar-plugin </artifactId>
<version> 2.3.2 </version>
<configuration>
<includes>**/src/*</includes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>spacecheck.SpaceCheck</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
I didn't use to have the 'includes' clause; as near as I can tell, that's what the example I got pointed to told me to do to fix the problem. It does not.
When I attempt to build, I get:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-jar-plugin:2.3.2:jar (default-jar) on
project SpaceCheck: Unable to parse configuration of mojo
org.apache.maven.plugins:maven-jar-plugin:2.3.2:jar for parameter
includes: Cannot assign configuration entry 'includes' with value
'*/src/' of type java.lang.String to property of type
java.lang.String[] -> [Help 1]
The "Help 1" link points me to the tutorial that I followed to get this far.
The problem I have with the tutorial is that it doesn't explain how things work -- it gives you an example and expects you to extract general workings from the example. There's nothing wrong with examples, but they rarely match exactly what one wants to do.
I'm sure many people can tell me what's wrong, and I would appreciate it. But it would be even better if they could ALSO tell me where this is explained, not just where there is an example that does something similar. The explanation, to be complete, would explain what element needs to be added, just where in the XML that goes, and what the various options are for the thing that goes there.
Instead of
<includes>**/src/*</includes>
try
<includes>
<include>**/src/*</include>
</includes>
And if you are learning Maven you definitely want to check out The Complete Reference.
Since you're asking for the documentation (and not the direct answer), have a look at http://maven.apache.org/guides/mini/guide-configuring-plugins.html
The problem is maven version
Following format for list/set is support in maven 3.3.9 and onward versions but in lower versions it not supported.
<includes>**/src/*</includes>
But in maven version less than 3.3.9, above is not supported
To fix make it backward compatible
<includes>
<include>**/src/*</include>
</includes>
PS: for more details check this link
Related
Is there a way to configure the asciidoc-maven-plugin to include https-resources? I did some research and found the follwing (interesting) information, however, was not able to solve the problem according to the hints provided:
https://github.com/asciidoctor/asciidoctor/issues/1049
https://github.com/asciidoctor/asciidoctor-maven-plugin/issues/153
The latter link seemed to adress the exact problem I have, however, upgrading / changing versions did not have any effect.
The following pom.xml file is a minimum working example that allows you to replicate the problem:
<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>de.myproject</groupId>
<artifactId>my-project</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<properties>
<revision>1.0.0-SNAPSHOT</revision>
<asciidoctor.maven.plugin.version>2.2.1</asciidoctor.maven.plugin.version>
<asciidoctorj.diagram.version>2.2.0</asciidoctorj.diagram.version>
<asciidoctorj.version>2.5.2</asciidoctorj.version>
<jruby.version>9.2.17.0</jruby.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>${asciidoctor.maven.plugin.version}</version>
<executions>
<execution>
<id>output-html5</id>
<phase>generate-resources</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<sourceDirectory>src/main/docs</sourceDirectory>
<outputDirectory>target/docs</outputDirectory>
<backend>html5</backend>
<doctype>book</doctype>
<attributes>
<safe-mode>UNSAFE</safe-mode>
<allow-uri-read>true</allow-uri-read>
</attributes>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj</artifactId>
<version>${asciidoctorj.version}</version>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-complete</artifactId>
<version>${jruby.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Now, if I save the following .adoc-file to the src/main/docs folder and run mvn clean install, I just get a notice Unresolved directive in my-project.adoc - include https://raw.githubusercontent.com/asciidoctor/asciidoctor/master/README.adoc instead of the actual document:
= my-project
include::https://raw.githubusercontent.com/asciidoctor/asciidoctor/master/README.adoc[]
However, if I donwload the above document (README.adoc) and reference it locally, I get the desired result. But this is not the way I want to include documentation by first downloading the file and then referencing it locally.
Does someone have an idea?
The idea is to only manage a single Maven project that contains all documentation including documentation from related projects that are also in our Gitlab repository. That is why I wanted to reference .adoc-files in those related projects by using include::https://concreteURLToAdocFile.
However, we realized, that it is a better idea to use the maven-dependency-plugin to first copy the .adoc-files from the other projects and then reference them locally.
This solution solved our concrete problem, however, it did not answer my original question.
For the last few days, I have been trying to get the code for a REST-API client being generated into my project using the openapi-generator-maven-plugin. However, Maven fails in the compile-Phase as soon as it realizes that the third-party dependencies just introduced by the generated code have not been resolved yet. As the code generation itself works, my problem seems to be rather general and related to what's happening after code is being generated.
This is a sample POM, containing the copy-pasted contents of their own README on how to set the plugin up:
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>openapi-generator-maven-plugin-error-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>5.0.0</version>
<!-- /RELEASE_VERSION -->
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/json/petstore.json</inputSpec>
<generatorName>java</generatorName>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Running mvn clean compile should generate the sources, and it does. However, as soon as the maven-compiler-plugin kicks in right after the code is being generated, it sees newly introduced package and symbol references in the generated code and consequently fails.
So I have tried to figure out how to install said dependencies, AFTER generation, but BEFORE compilation, but completely failed to do so. I suspect I need to use the maven-depndencies-plugin, but due to my limited knowledge of Maven and even more limited knowledge of how its plugins work, I am completely lost. I have tried adding the maven-dependency-plugin to my POM, but Maven completely ignores it and does not run it at all. I have tried to bind the resolve goal to the compile phase to no avail.
I would have expected code generation to not be a too uncommon thing to do with Maven, so I am a bit surprised it is actually so hard to pull off. Am I on the right tracks here? What exactly am I missing to have those transitive dependencies introduced in the generated code installed before the compiler is trying to compile them?
I've spent the entirety of yesterday and the start of today trying to find out why Codenvy is using Java 8, but cannot find the JavaFX library that is included with it. I've looked through the files of the machine and cannot find it anywhere. I've also attempted to add it natively as a Source jar, but Codenvy seems to have removed support for this. On top of this, their tutorial page for adding source jars has been replaced with how to set up Che. I just use the Codenvy website and keep everything on the cloud.
So my problem is that I cannot get sound (MP3) to play. I tried the project on a workspace I set up in Codenvy previously, and it worked without an issue... yet a workspace made post Codenvy Beta release doesn't work, the JavaFX library just isn't there. The workspace from the older Codenvy doesn't have a stack (see below). Where as the newer projects do. I've tried workspaces with all the stacks that include Java, and still nothing. I did put the project into the old workspace and it worked flawlessly, but the old workspace doesn't have all the features of the newer ones, like ctrl+space for auto-complete, ect. I may aswell be using Notepad.
Is anyone else experiencing this, and is there a way to fix it?
Below is also my pom.xml so you can see the configuration.
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>TMMOJ</groupId>
<artifactId>TMMOJ</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<argLine>-Xmx1024m</argLine>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<compilerVersion>1.5</compilerVersion>
</configuration>
</plugin>
</plugins>
Managed to get this working by adding the jfxrt.jar from the JDK .tar.gz from the official java website to a lib folder, and adding it as a dependency (as described in one of the answers to this question JavaFX 2 as a Maven dependency). This solved the problem.
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.
I am trying to implement a new XPath PMD rule based on the example from the book "Jenkins Continuous Integration Cookbook".
My pom file's relevant section:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<configuration>
<targetJdk>1.6</targetJdk>
<format>xml</format>
<rulesets>
<ruleset>password_ruleset.xml</ruleset>
</rulesets>
</configuration>
</plugin>
</plugins>
</reporting>
I have the file 'password_ruleset.xml' sitting in the root of my maven project and it looks as follows:
<?xml version="1.0"?>
<ruleset name="STUPID PASSWORDS ruleset"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>
Lets find stupid password examples
</description>
<rule name="NO_PASSWORD"
message="If we see a PASSWORD we should flag"
class="net.sourceforge.pmd.rules.XPathRule">
<description>
If we see a PASSWORD we should flag
</description>
<properties>
<property name="xpath">
<value>
<![CDATA[
//VariableDeclaratorId[#Image='PASSWORD']
]]>
While executing i got the following error:
Failure executing PMD: Couldn't find the class net.sourceforge.pmd.rules.XPathRule
Checking which libraries contains this class i realized it's 'pmd' itself. I tried to add the dependency to the dependencies section without luck.
Where and what should i change to overcome this?
Please see the whole setup in github:
https://github.com/dave00/pmdcustomrule
A friend of mine resolved my problem via github:
https://github.com/mnyeste/pmdcustomrule/commit/ad2f04e33d2a5a04ef95d059d64a258ebca5b7be
Summary:
PMD API change 4.3 -> 5.0 Class net.sourceforge.pmd.rules.XPathRule
has been renamed to net.sourceforge.pmd.lang.rule.XPathRule
Maven PMD plugin version 3.2 is using PMD 5.1.2
Anyone interested can now pull my example project from github to see this working.