How to exclude project from multi module Maven License Plugin aggregation? - java

I'm having trouble trying to ignore some modules when I add headers to my files using maven license plugin. The way I am trying to do is to put the modules path in the excludes tag. Here is the plugin in pom.xml:
<plugin>
<groupId>com.mycila.maven-license-plugin</groupId>
<artifactId>maven-license-plugin</artifactId>
<version>1.10.b1</version>
<executions>
<execution>
<goals>
<goal>format</goal>
</goals>
<phase>validate</phase>
<configuration>
<header>header.txt</header>
<aggregate>true</aggregate>
<excludes>
<exclude>**/a/**</exclude>
<exclude>**/b/**</exclude>
<exclude>**/c/**</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
This is the way I'm trying to ignore the projects inside this parent pom.xml. I have already tried also with
${project.basedir}/a/
and
${basedir}/a/
Thank you in advance.

Please try:
<excludes>
<exclude>a/**</exclude>
<exclude>b/**</exclude>
<exclude>c/**</exclude>
</excludes>

Related

why maven-compiler-plugin exclude disable

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/Application.java</exclude>
</excludes>
</configuration>
</plugin>
this is my pom.xml , maven-compiler-plugin.version is 3.8.1 .
but i see the Applciation.class still in my jar package by maven
You are looking at the wrong location. From what I see in the screenshot, you've found some Application file from the External Libraries. What the maven-compiler-plugin does is to generate the target folder. That's where the class file should be excluded from. Check the existence of the file class under:
target/classes/...
And don't forget to run mvn clean install before (with emphasis on clean - this will wipe out your target folder)
In a project, I had to do a similar thing, due I need to exclude the module-info.java. I resolved using this configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<excludes>
<exclude>**/module-info.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
If you want the entire project you can get it from GitHub. I hope this helps.

Splitting a list of test methods into two JARs using Maven

I have read some Q/A about how to generate two JARs using a single Maven pom.xml file, but I am having troubles applying what I read to my specific case since I am a beginner with Maven.
I have a package used for running some tests in my CI. The structure of the Maven project is as follow:
pom.xml
src
|_ main
|_ java
|_ model
| |_ Something.java
|_ suites
|_ TestSuiteA.java
|_ TestSuiteB.java
|_ TestSuiteC.java
Right now I am generating a single JAR file which is destined to be used in the CI to run those tests. What I would like to do is creating two JARs:
A JAR for TestSuiteA and TestSuiteB
A JAR for TestSuiteC, as those tests need to be ran in a separate part of the CI
Right now, the pom.xml looks like that:
<build>
<plugins>
<plugin>
<groupId>org.testpackage</groupId>
<artifactId>testpackage-maven-plugin</artifactId>
<version>0.3.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>fatjar</goal>
</goals>
<configuration>
<package-name>net.myorg.uitests.suites</package-name>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I tried using excludes and includes directive to have two JARs including different files:
<build>
<plugins>
<plugin>
<groupId>org.testpackage</groupId>
<artifactId>testpackage-maven-plugin</artifactId>
<version>0.3.1</version>
<executions>
<!-- First JAR -->
<execution>
<id>build-first</id>
<phase>package</phase>
<goals>
<goal>fatjar</goal>
</goals>
<configuration>
<classifier>client</classifier>
<!-- Exclude TestSuiteC -->
<excludes>
<exclude>**/suites/TestSuiteC</exclude>
</excludes>
<package-name>net.antidot.bo.uitests.suites</package-name>
</configuration>
</execution>
<!-- Second JAR -->
<execution>
<id>build-second</id>
<phase>package</phase>
<goals>
<goal>fatjar</goal>
</goals>
<configuration>
<classifier>client</classifier>
<!-- Exclude everything except TestSuiteC -->
<excludes>
<exclude>**/suites/TestSuite*</exclude>
</excludes>
<includes>
<include>**/suites/TestSuiteC</include>
</includes>
<package-name>net.antidot.bo.uitests.suites</package-name>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
However, I am unsure about what to do next. I tried running mvn package but it only produced one JAR file.
Is this the correct approach? If yes, what step should I take next?

Sign all jars and wars maven project

How to sign all jars and wars that are generated in project when i clean and build with maven ? Is there such plugin and instruction how to use it. I found this http://maven.apache.org/plugins/maven-jarsigner-plugin/usage.html while searching the internet but there is no good instruction how to use or test it.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>sign</id>
<phase>install</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<archiveDirectory>jars location</archiveDirectory>
<includes>
<include>**/*.jar</include>
</includes>
<keystore>/path/to/keystore.jks</keystore>
<alias>...</alias>
<storepass>...</storepass>
<keypass>...</keypass>
</configuration>
</plugin>
This code worked for me

Maven Get Specific Classes

Is there a way that I can get maven to only include specific .class files when importing dependencies into uber jar (shade). I'm looking for a way to get files that contain "Client" in their name to be pulled out of the dependency jars and added to the final jar. Any help would be wonderful.
You should be able to use the maven-dependency-plugin like this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId><!--dependency groupId--></groupId>
<artifactId><!--dependency artifactId--></artifactId>
<version><!--depedency version--></version>
<includes>**/*Client*.java</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
If you are using the Maven Shade Plugin, you can a filter, which will allow you to filter which artifacts get shaded, but as well as which classes to exclude or include.
Here's the example they provide:
<filters>
<filter>
<artifact>junit:junit</artifact>
<includes>
<include>org/junit/**</include>
</includes>
<excludes>
<exclude>org/junit/experimental/**</exclude>
</excludes>
</filter>
</filters>

Maven / plugin : force fail is some jars are available in the dependency tree

I am looking for a Maven 3 plugin checking (and force compilation error) if some jars are available in the dependency tree.
The idea is to prevent from having some jars in the WEB-INF/lib folder (in my case, more than one SLF4J binding)
Regards
You might need the maven-enforcer-plugin.
Its set of rules includes a rule to ban specific dependencies from your project. It's the "Banned Dependencies" rule.
Here's a sample plugin configuration from their docs:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>enforce-banned-dependencies</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<excludes>
<exclude>org.apache.maven</exclude>
<exclude>org.apache.maven:badArtifact</exclude>
<exclude>*:badArtifact</exclude>
</excludes>
<includes>
<!--only 1.0 of badArtifact is allowed-->
<include>org.apache.maven:badArtifact:1.0</include>
</includes>
</bannedDependencies>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>

Categories