I have created a simple maven project to create shaded jar. I built it using mvn clean compile .It creates jar file but after extracting it i don't see .class files corresponding to my project java source files. I see clearly below message when i build but don't see any .class files under target dir.
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # PersonalizationFeeder ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 10 source files to Documents/PersonalizationFeeder/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
What is the problem here? My pom.xml looks like this.
<?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">
<parent>
<artifactId>data-analytics</artifactId>
<groupId>com.wooplr</groupId>
<version>0.0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>PersonalizationFeeder</artifactId>
<packaging>jar</packaging>
<properties>
<userlib.dir>Documents/userlibs</userlib.dir>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>${spark.version}</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming-kafka_2.10</artifactId>
<version>${spark.version}</version>
</dependency>
<dependency>
<groupId>com.wooplr</groupId>
<artifactId>jedis</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${userlib.dir}/jedis-2.7.3.jar</systemPath>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>junit:junit</exclude>
<exclude>org.apache.maven:lib:tests</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<!--<artifact>*:*</artifact>-->
<excludes>
<excludeScope>system</excludeScope>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Problem solved...!! In one of the dependency jars, there is licenced jar and because of which it couldn't build properly. To solve the problem,I had to extract that particular dependency jar and remove .RSA,.DSA and *.SF files from META-INF/ dir and then make it jar using jar -cf command and then use this new jar as dependency. It worked fine for me. Thanks all.
Related
I'm having trouble getting JaCoCo to work with Maven. I keep running into either
Skipping JaCoCo execution due to missing execution data file.
Or
The parameters 'rules' for goal org.jacoco:jacoco-maven-plugin:0.8.2:check are missing or invalid
I also can't seem to get JaCoCo to run with just mvn clean test instead I have to run mvn clean test jacoco:report or mvn clean test jacoco:check
I've tried a variety of methods of editing my POM file, such as adding configuration for destFile and dataFile, as well as the POM settings here: https://howtodoinjava.com/junit5/jacoco-test-coverage/ and here https://www.lambdatest.com/blog/reporting-code-coverage-using-maven-and-jacoco-plugin/ . Any help would be greatly appreciated. Below is my POM file
<?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>com.NAME.PROJECTNAME</groupId>
<artifactId>PROJECTNAME</artifactId>
<version>1.0-SNAPSHOT</version>
<name>PROJECTNAME</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17.0.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<configuration>
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- attached to Maven test phase -->
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<mainClass>HelloFX</mainClass>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
This is because you are using <pluginManagement> tag, and <plugins> are put inside it.
As per the Maven documentation on <pluginManagement>,
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 or in the current POM. The children have every right to override pluginManagement definitions.
In short, you will use <pluginManagement> in case of multi-module Maven project. Here is a bit more explanation in this answer.
I removed the <pluginManagement> tag from pom.xml and now the build is working and Jacoco report is getting generated.
-> mvn clean verify
...
[INFO] --- jacoco-maven-plugin:0.8.2:prepare-agent (default) # PROJECTNAME ---
[WARNING] The artifact xml-apis:xml-apis:jar:2.0.2 has been relocated to xml-apis:xml-apis:jar:1.0.b2
[INFO] argLine set to -javaagent:/home/codejournal/.m2/repository/org/jacoco/org.jacoco.agent/0.8.2/org.jacoco.agent-0.8.2-runtime.jar=destfile=/tmp/maven-jacoco/target/coverage-reports/jacoco-unit.exec
...
...
[INFO] --- jacoco-maven-plugin:0.8.2:report (report) # PROJECTNAME ---
[INFO] Loading execution data file /tmp/maven-jacoco/target/coverage-reports/jacoco-unit.exec
[INFO] Analyzed bundle 'PROJECTNAME' with 1 classes
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) # PROJECTNAME ---
[INFO] Building jar: /tmp/maven-jacoco/target/PROJECTNAME-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.141 s
[INFO] Finished at: 2022-04-24T02:18:30+05:30
[INFO] ------------------------------------------------------------------------
-> cat target/site/jacoco/jacoco.csv
GROUP,PACKAGE,CLASS,INSTRUCTION_MISSED,INSTRUCTION_COVERED,BRANCH_MISSED,BRANCH_COVERED,LINE_MISSED,LINE_COVERED,COMPLEXITY_MISSED,COMPLEXITY_COVERED,METHOD_MISSED,METHOD_COVERED
PROJECTNAME,io.codejournal.maven.jacoco,Hello,7,0,0,0,3,0,2,0,2,0
I am developing a Java agent using ByteBuddy, and I need the ByteBuddy library .jar file to be included in the agent .jar file. So far, in order for the agent to run smoothly, I need the ByteBuddy library .jar files to be present in the classpath both at compile time and at runtime. How can I bundle a .jar file such that the agent is self-contained ?
I tried using the shade plugin (as demonstrated here) as well as a few other techniques found on the web, but none of them seem to really include the dependencies in the .jar file, only a reference.
For every technique, I looked in the resulting .jar file (weighs around 5kB every time) and only found the .class files corresponding to the classes I had written, no class files related to ByteBuddy. To be clear, the ByteBuddy library .jar file weighs about 3MB, so I expect my self-contained agent .jar file to weigh around 3MB, as my code is light.
Below is my pom.xml file :
<?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>com.captainhook.agent</groupId>
<artifactId>agent</artifactId>
<version>1.0-SNAPSHOT</version>
<name>agent</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>bytebuddy</artifactId>
<version>1.12.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/byte-buddy-1.12.3.jar</systemPath>
</dependency>
<dependency>
<groupId>net.bytebuddy.agent</groupId>
<artifactId>bytebuddy-agent</artifactId>
<version>1.12.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/byte-buddy-agent-1.12.3.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
And this is the output I get after running mvn package :
[...]
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # agent ---
[INFO]
[INFO] --- maven-assembly-plugin:2.2-beta-5:single (default) # agent ---
[INFO] Building jar: /home/bluesheet/svn/stages/captainhook/2021/ijp-frida-jdi-bytebuddy/1/dbg/shared/agent/maven-test/agent/target/agent-1.0-SNAPSHOT-jar-with-dependencies.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.339 s
[INFO] Finished at: 2021-12-31T12:26:59+01:00
[INFO] ------------------------------------------------------------------------
EDIT:
So, the reason why all the previous techniques were not working was because of the way I specified the dependencies. This doesn't get included :
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>bytebuddy</artifactId>
<version>1.12.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/byte-buddy-1.12.3.jar</systemPath>
</dependency>
while this does :
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.12.6</version>
</dependency>
I am new to maven so I blindly copy-pasted a piece of code to include the dependencies and I did not spot the error...
Thank you very much !
Sounds like you need to use the "maven-assembly-plugin" with the "jar-with-dependencies" descriptor.
E.g. here is a full example pom file with a dependency on ByteBuddy:
<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>test.example</groupId>
<artifactId>packaging-example</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>test.example.TestByteBuddy</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.12.6</version>
</dependency>
</dependencies>
</project>
And for the sake of completeness - here is the main class also :
package test.example;
import net.bytebuddy.ByteBuddy;
public class TestByteBuddy
{
public static void main(String... args) throws Exception
{
System.out.println("Hello Byte Buddy Class - " + ByteBuddy.class);
}
}
Building this will produce an additional file in the target directory - packaging-example-1.0-SNAPSHOT-jar-with-dependencies.jar
Then you should be able to run it simply with :
java -jar packaging-example-1.0-SNAPSHOT-jar-with-dependencies.jar
to give you the output:
Hello Byte Buddy Class - class net.bytebuddy.ByteBuddy
I try to run unit tests when surefire by default skipped tests in pom.xml.
this is my pom.xml surefire 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>org.example</groupId>
<artifactId>jenkins-tutorial</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<skipTests>true</skipTests>
<junit.jupiter.version>5.0.0-M5</junit.jupiter.version>
<junit.vintage.version>4.12.0-M5</junit.vintage.version>
<junit.platform.version>1.0.0-M5</junit.platform.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.vintage.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>hello</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<compilerVersion>1.8</compilerVersion>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/libs
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>
ir.moke.jenkins.MyLib
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<includes>
<include>**/*Test</include>
</includes>
<skipTests>${skipTests}</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
and i run this command :
mvn clean compile test -DskipTests=false
this is console log:
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # jenkins-tutorial ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /home/mah454/Programming/java/jenkins-tutorial/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) # jenkins-tutorial ---
[INFO] Tests are skipped.
according to this document:
https://maven.apache.org/surefire/maven-surefire-plugin/examples/skipping-tests.html
I want to run test in this case .
How can fix this problem ?
Here's my project: https://github.com/mah454/jenkins-tutorial
Rename SampleTestClass in your project to SampleTest and then you can run the command:
mvn test -DskipTests=false
The default name for a test class must end with Test.
Or you can change the includes configuration to:
<includes>
<include>*TestClass</include>
</includes>
This problem happens often, more and more, because the people do not read the documentations, example: https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
Pls use the postfix Test and not TestClass in the file name. You can freely use the postfix TestCase but it is already obsolete. If you rely on the defaults, you would NOT use the sections
<includes>
<include>xxx</include>
</includes>
The plugins in CI rely on the default postfixes, no need to reconfigure them!
My Maven project uses an external library as a dependency, com.sk89q.intake:intake, which I'm trying to package into my jar via the maven-shade-plugin. When building the project, the resulting jar does not contain any of the class files of com.sk89q.intake:intake. During the build process, I get this message, but the build continues on and succeeds:
[INFO] --- maven-shade-plugin:2.4.2:shade (default) # EventManagerPlugin
[INFO] No artifact matching filter com.sk89q.intake:intake
Why is this happening? I'm able to download, access, and use the dependency in my project, so there shouldn't be anything wrong with naming of the artifact.
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>deletethis.eventmanager</groupId>
<artifactId>EventManagerPlugin</artifactId>
<version>1.0.0-beta1</version>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>maven.sk89q.com</id>
<url>http://maven.sk89q.com/repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.intake</groupId>
<artifactId>intake</artifactId>
<version>4.2-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<archive>
<manifestEntries>
<Built-By>deletethis</Built-By>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>com.sk89q.intake:intake</artifact>
<includes>
<include>com/sk89q/intake/**</include>
</includes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>com.sk89q.intake</pattern>
<shadedPattern>deletethis.eventmanager.lib.com.sk89q.intake</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
As you can see, I am including the com.sk89q.intake:intake artifact. I have looked through the maven-shade-plugin documentation and don't see what I'm doing wrong. The naming is consistent with everything I have found online; that is, groupId:artifactId.
I have also tried building without the <relocation> class relocation tags to see if they were interfering.
It may be useful to know that I'm using M2Eclipse and building with the clean install goals.
The problem is that your are declaring the com.sk89q.intake:intake dependency with the provided scope.
Provided dependency are expected to be provided by the container at runtime so the maven-shade-plugin will not add it to your shaded jar. As such, you need to remove the provided scope from the dependency declaration:
<dependency>
<groupId>com.sk89q.intake</groupId>
<artifactId>intake</artifactId>
<version>4.2-SNAPSHOT</version>
</dependency>
Relevant build log after this change:
[INFO] --- maven-shade-plugin:2.4.2:shade (default) # test ---
[INFO] Including com.sk89q.intake:intake:jar:4.2-SNAPSHOT in the shaded jar.
[INFO] Including com.google.guava:guava:jar:18.0 in the shaded jar.
[INFO] Including com.google.code.findbugs:jsr305:jar:3.0.0 in the shaded jar.
This must be mostly a newbie Maven question.
Since SwingX migrated to Kenai, there are warnings all over the website that many links are broken.. so here is my best attempt.
I went to https://java.net/projects/swingx/downloads/directory/releases
Clicked on "SwingX 1.6.4 All - Sources" (really a non-intuitive, hit-or-miss choice for me, but perhaps it's a naming convention other people understand?)
This downloads swingx-all-1.6.4-sources.jar (why is it even a jar and not a zip?)
However, this source jar does not contain POM.XML.
So, I downloaded swingx-all-1.6.4.jar from the same link, renamed it to .zip, inflated. It does contain
META-INF\maven\org.swinglabs.swingx\swingx-all\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>
<parent>
<artifactId>swingx-project</artifactId>
<groupId>org.swinglabs.swingx</groupId>
<version>1.6.4</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>swingx-all</artifactId>
<packaging>jar</packaging>
<name>SwingX Complete</name>
<description>A Maven project to aggregate all modules into a single artifact.</description>
<properties>
<project.generatedDependencies>${project.generatedSourcesDirectoy}/dependencies</project.generatedDependencies>
</properties>
<!-- make the dependent swingx modules optional, since we're aggregating -->
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>swingx-graphics</artifactId>
<version>${project.version}</version>
<type>jar</type>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>swingx-core</artifactId>
<version>${project.version}</version>
<type>jar</type>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>swingx-mavensupport</artifactId>
<version>${project.version}</version>
<type>jar</type>
<scope>compile</scope>
<optional>true</optional>
</dependency>
</dependencies>
<profiles>
<profile>
<id>jvnet-release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>src-dependencies</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<classifier>sources</classifier>
<includeGroupIds>${project.groupId}</includeGroupIds>
<excludeArtifactIds>swingx-mavensupport</excludeArtifactIds>
<failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
<outputDirectory>${project.generatedDependencies}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>add-dependencies-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.generatedDependencies}</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-dependencies-resource</id>
<phase>generate-resources</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${project.generatedDependencies}</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.generatedAnnotations}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
When I change to the above directory where POM.XML is located and do mvn install, it certainly builds a lot of stuff.. but also says:
[INFO] skip non existing resourceDirectory
F:\swingx\swingx-all-1.6.4\META-INF\m
Maven\org.swinglabs.swingx\swingx-all\src\main\resources
That's because the src directory is nonexistent. Which makes sense, because the .jar files in question is said to be binaries only, but I was hoping some Maven target would download sources or something... and if it's binary only, why does it need to be built? Confused.
At that point, I could probably either copy the src directory from the first zip file to the second, or copy the pom.xml from the second file to the first.. but I am having a feeling I am missing something, and there has to be a more straightforward way.
BTW, there is a third file at the same web page, swingx-mavensupport-1.6.4.jar
So I downloaded that, renamed it to .zip, inflated, found this file:
META-INF\maven\org.swinglabs.swingx\swingx-mavensupport\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>
<parent>
<artifactId>swingx-project</artifactId>
<groupId>org.swinglabs.swingx</groupId>
<version>1.6.4</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>swingx-mavensupport</artifactId>
<name>SwingX Maven Support</name>
</project>
Changed to its directory and ran mvn.install
However, that complained at the lack of a whole lot of files.
I must be getting it all wrong. What's the right way?
Use the following URL for SVN checkout: https://svn.java.net/svn/swingx~svn.
In trunk there is a correct pom.xml file (actualy many of them for different artifacts), so you can easily build the project yourself.
swingx-all-1.6.4-sources.jar (why is it even a jar and not a zip?)
That's the default way sources are packaged and distributed in Maven.