Add a new line between dependencies via google sort pom plugin - maven

Is there a way to add a new line between each dependency via the google sort pom plugin or any other plugin.
Current POM, sorted via google sort pom plugin
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.5</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<version>1.4.10</version>
</dependency>
I'm trying to achieve
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.5</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<version>1.4.10</version>
</dependency>
My current pom plugin
<plugin>
<groupId>com.google.code.sortpom</groupId>
<artifactId>maven-sortpom-plugin</artifactId>
<version>${com.google.code.sortpom}</version>
<configuration>
<predefinedSortOrder>custom_1</predefinedSortOrder>
<sortDependencies>groupId,artifactId</sortDependencies>
<sortPlugins>groupId,artifactId</sortPlugins>
<sortProperties>false</sortProperties>
<createBackupFile>false</createBackupFile>
<lineSeparator>\r\n</lineSeparator>
<expandEmptyElements>false</expandEmptyElements>
<keepBlankLines>true</keepBlankLines>
<nrOfIndentSpace>-1</nrOfIndentSpace>
<verifyFail>Warn</verifyFail>
</configuration>
<executions>
<execution>
<goals>
<goal>sort</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
</plugin>

At the moment the maven-sortpom-plugin does not have an automatic way of inserting blank lines between dependencies.
However, if you have a empty line between two existing dependencies, the plugin will not remove the line during sorting since you use the configuration option <keepBlankLines>true</keepBlankLines>

Its just an XML file
Just use your IDE's built in XML formatter to format the pom.xml file however you want. Both Eclipse and Intellij IDEA have formatters for XML files.

Related

Issue on maven(pom.xml) settings on QueryDsl, MapStruct, Lombok and intellij

My Problem -
QueryDsl and MapStruct only generate classes on maven install but i want it to re-generate on source code change (with springboot devtool auto restart). now it does nothing on source code change other than restart
My pom.xml as below
....
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
.....
<build>
<plugins>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<dependencies>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${org.projectlombok.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/annotations</outputDirectory>
<processors>
<processor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</processor>
<processor>org.mapstruct.ap.MappingProcessor</processor>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Intellij Setting
Annotation Processors
My Proccess -
Before Spring-boot Start i have to clean then install maven due to Qclass and MapperImpl. Also after maven install because of Qclass error, got to check "Module output directory" on "Store generated sources relative to:"
and everytime i change mapstruct mapper file i have do above things yet again which is very annoying
i have tried this solution but it didnt work .. :X
stackover flow solution
Please help
Thx :)
The best way to achieve that is to use the annotationProcessorPaths from the maven-compiler. It will do the job during the compilation phase of the project.
IntelliJ already configures the build appropriately based on the maven-compiler and will be able to detect your processors. I also know that in IntelliJ IDEA 2020.3 they are going to do some improvement around the processors that would improve the user experience.

How to exclude all vulnerabilities of hive-exec, which includes "shaded" dependency itself?

I must remove all "High Severity"-Vulnerabilities in "Dependency-check", which are generated through a maven-plugin. It is difficult to remove vulnerabilities of "hive-exec".
An example of result-html-file is like this.
hive-exec-3.1.0.jar (shaded: org.apache.parquet:parquet-hadoop:1.10.0)
File Path: C:\Users\MYNAME\.m2\repository\org\apache\hive\hive-exec\3.1.0\
hive-exec-3.1.0.jar\META-INF/maven/org.apache.parquet/parquet-hadoop/pom.xml
this "...\hive-exec-3.1.0.jar\META-INF/maven/org.apache.parquet/parquet-hadoop/pom.xml" should be removed!
I could remove most of Vulnerabilities using < exclude > -tag in each < dependency > or changing the version.
I also tried to exclude this "parquet-hadoop" in my pom file...
<dependencies>
...
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>3.1.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.parquet</groupId>
<artifactId>parquet-hadoop-bundle</artifactId>
</exclusion>
...
</exclusions>
</dependency>
</dependencies>
But it couldn't remove this "parquet-hadoop-bundle", because they are "shaded" in the "hive-exec".
A file called hive-exec-3.1.0.pom inside the hive-exec-3.1.0.jar shades this "parquet-hadoop". The hive-exec-3.1.0.pom has the following contents...
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>build-exec-bundle</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>org.apache.hive:hive-common</include>
...
<include>org.apache.parquet:parquet-hadoop-
bundle</include>
I also tried to remove them with shade-plugin in my pom file. But It doesn't work.
I'll be very happy if someone has experience with this kind of problem.
A college found the solution.
...
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>3.1.0</version>
<classifier>core</classifier>
<exclusions>
...
We can specify the jar of the hive-exec with the "classifier"-tag and the value-"core". This "core" includes only the essential part of the "hive-exec". In this way I could remove all high and middle vulnerabilities.

How to exclude a dependency defined in the pom.xml from a plugin defined in the same pom

I have a pom.xml in which I have a dependency defined as:
<dependency>
<groupId>abc.xyz.pig</groupId>
<artifactId>pig</artifactId>
<version>10</version>
<scope>provided</scope>
</dependency>
I want to define a new plugin in the same file, for which I need a higher version of the same dependency. How do I make my plugin use a higher version of the dependency and ignore the lower version defined above?
I tried adding the dependency of the newer version in my plugin definition like this, but it didn't work:
<plugin>
<groupId>my_plugin</groupId>
<artifactId>my_plugin_artifact</artifactId>
<version>0.1.1</version>
<executions>
<execution>
<goals>
<goal>my_plugin_goal</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>abc.xyz.pig</groupId>
<artifactId>pig</artifactId>
<version>11</version>
</dependency>
</dependencies>
</plugin>

How to deploy in a gwt-maven project

first of all, I'm not sure which folders and files i have to deploy in a gwt-maven project
I've got:
.gwt
.settings
bin
src/main/java
target
war
pom.xml
I'm pretty sure, I've to deploy the pom.xml somehow and the target folder. But my target folder doesn't contain a pom.xml which I need for deploying on a jetty server
Second:
I've installed maven on my webserver, but apart from embedding the jetty-maven-plugin in the pom.xml (by
org.eclipse.jetty
jetty-maven-plugin
)
I have absolutely no clue how to get this project running on a jetty server.
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
SiedlerVonCatanC
SiedlerVonCatanC
war
src/main/java
src/main/java
*/.java
maven-compiler-plugin
3.1
1.7
1.7
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
</goals>
<configuration>
<module>main.java.de.swp.catan.SiedlerVonCatanC</module>
<runTarget>SiedlerVonCatanC.html</runTarget>
<hostedWebapp>${webappDirectory}</hostedWebapp>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<!-- GWT -->
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>2.5.1</version>
</dependency>
<!-- SmartGWT -->
<dependency>
<groupId>com.smartgwt</groupId>
<artifactId>smartgwt</artifactId>
<version>3.0</version>
</dependency>
<!-- Event Service -->
<dependency>
<groupId>de.novanic.gwteventservice</groupId>
<artifactId>gwteventservice</artifactId>
<version>1.2.0</version>
</dependency>
<!-- Java-Mail -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
<!-- Apache Commons -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.3</version>
</dependency>
<!-- htmlunit (wird im Projekt irgendwo genutzt) -->
<!-- <dependency> <groupId>net.sourceforge.htmlunit</groupId> <artifactId>htmlunit</artifactId>
<version>2.4</version> </dependency> -->
<!-- Guice -->
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
</dependency>
<!-- Connector for JDBC -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.25</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>com.smartgwt</id>
<url>http://www.smartclient.com/maven2</url>
</repository>
</repositories>
<version>0.2</version>
have the maven-jetty-plugin included in your pom , under plugins and then you can run it as
mvn jetty:run
thanks
If you want to use maven plugin to run embedded jetty for development then easy way using command-line (which I recommend for start) is:
Edit: Please note this is not related to the existing project.Its process from scratch. Just run these command from a new directory where you would like a new gwt project to be created.
Dowload gwt maven plugin http://mojo.codehaus.org/gwt-maven-plugin/. In command line list you can see it as org.codehaus.mojo:gwt-maven-plugin (Maven plugin for the Google Web Toolkit.) I see that you have this plugin in POM, but if you are at loss here the simple steps from command-line to achive this are:
mvn archetype:generate
enter org.codehaus.mojo:gwt-maven-plugin in search prompt
comfirm the resutl with enter
set-up the maven project configuration as prompted
run the project with mvn gwt:run from the folder where you have pom.xml
These two steps will run a sample project for you which you can further modify and experiment while learning how it works.,
As for directories:
The maven compiles all your stuff in target directory and that is used for deployment or running embedded jetty.

maven ignoring findbugs suppressFBWarnings annotation

I have 2 projects that I am using the FindBugs plugin in maven to identify bugs. I am also using the #SuppressFBWarnings annotation to ignore specific bugs.
With the first project, I added the dependancies to the pom.xml and both the findbugs report and the annotation worked fine. With the second project, the report gets generated, but it still identifies bugs that I have suppressed using the annotation.
I run mvn clean install site to generate the reports on my machine in the build folder.
Each of the 2 projects I mentioned, have sub-projects with their own pom.xml files in their sub-directories, so in the parent directory, I also have a pom.xml. This directory layout is mirrored identically in both of the main projects.
Here is the XML I added to the parent poms under the <reporting> tag:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<xmlOutput>true</xmlOutput>
<findbugsXmlOutput>true</findbugsXmlOutput>
<fork>true</fork>
<threshold>Low</threshold>
<effort>Min</effort>
</configuration>
</plugin>
Also, in this same parent pom, I added this to the <dependencyManagement><dependencies> section:
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>2.0.1</version>
</dependency>
This is identical in both of the main projects poms.
Now, in the sub-projects where I actually use the #SuppressFBWarnings annotation, and only in that particular sub-project, I have this under <dependencies>:
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>2.0.1</version>
</dependency>
Also, this is mirrored in the other working project. I copied and pasted directly.
One project works perfect and I can successfully suppress false positives. The other project completely ignores the #SuppressFBWarnings anotation, and I can't seem to fix it.
Is there something I'm missing here?
I think that if an annotation is not found, instead of giving an error, it will just ignore it? How can I tell if its not found?
Hopefully this is a simple fix.
Thanks.
#SuppressFBWarnings was introduced with the annotation in version 3. That's why it should look like this:
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>3.0.1</version>
</dependency>
Try to add annotations artifcat to the plugin dependencies :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<xmlOutput>true</xmlOutput>
<findbugsXmlOutput>true</findbugsXmlOutput>
<fork>true</fork>
<threshold>Low</threshold>
<effort>Min</effort>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>2.0.1</version>
</dependency>
</dependencies>
</plugin>
Ensure that the dependency added is in between the dependencies tags.
Like this:
<dependencies>
<dependency>
<groupId>something</groupId>
<artifactId>something</artifactId>
<version>something</version>
</dependency>
<dependencies>

Resources