Im new to scala, Im trying to include scala project into my java project.
I have separate scala and java project and Im using scala in java.
It is working fine when I add scalaTest to my java project build path. Is there any way I can edit my pom.xml that automatically refer the scalaTest project while maven build?.
I have added scala dependency in my pom.xml
Or is there any way that I can include both java and scala files into my java project and run ?
If you the following pom.xml you should be able to compile Java and Scala sources from within the same project via mvn.
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>javaScala</artifactId>
<version>1.0-SNAPSHOT</version>
<name>javaScala</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDir>src/main/scala</sourceDir>
<testSourceDir>src/test/scala</testSourceDir>
<jvmArgs>
<jvmArg>-Xms64m</jvmArg>
<jvmArg>-Xmx1024m</jvmArg>
</jvmArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
Answers to my own question
Add Scala project in class path (buildpath) of java project.
Export Scala project as jar and import to your java project.
To include both java and scala in single java project, follow this.
Include java files into - src/main/java
Include scala files into - src/main/scala
Use this pom.xml
Download project from https://github.com/rthoma24/Java-Scala.git
maven commands
mvn compile
mvn exec:java -Dexec.mainClass=main.java.Test
<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>ted-gao</groupId>
<artifactId>scala-java-mix</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Scala-Java mixture</name>
<description>Showcase mixing Scala and Java</description>
<packaging>jar</packaging>
<build>
<plugins>
<!-- ensure that we use JDK 1.6 -->
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<!-- Run scala compiler in the process-resources phase, so that dependencies on
scala classes can be resolved later in the (Java) compile phase -->
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<!-- Run scala compiler in the process-test-resources phase, so that dependencies on
scala classes can be resolved later in the (Java) test-compile phase -->
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<!-- Add src/main/scala to source path of Eclipse -->
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/scala</source>
</sources>
</configuration>
</execution>
<!-- Add src/test/scala to test source path of Eclipse -->
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/scala</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<!-- to generate Eclipse artifacts for projects mixing Scala and Java -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<projectnatures>
<projectnature>org.scala-ide.sdt.core.scalanature</projectnature>
<projectnature>org.eclipse.jdt.core.javanature</projectnature>
</projectnatures>
<buildcommands>
<buildcommand>org.scala-ide.sdt.core.scalabuilder</buildcommand>
</buildcommands>
<classpathContainers>
<classpathContainer>org.scala-ide.sdt.launching.SCALA_CONTAINER</classpathContainer>
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
</classpathContainers>
<excludes>
<!-- in Eclipse, use scala-library, scala-compiler from the SCALA_CONTAINER rather than POM <dependency> -->
<exclude>org.scala-lang:scala-library</exclude>
<exclude>org.scala-lang:scala-compiler</exclude>
</excludes>
<sourceIncludes>
<sourceInclude>**/*.scala</sourceInclude>
<sourceInclude>**/*.java</sourceInclude>
</sourceIncludes>
</configuration>
</plugin>
<!-- When run tests in the test phase, include .java and .scala source files -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<includes>
<include>**/*.java</include>
<include>**/*.scala</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.9.0</version>
</dependency>
</dependencies>
</project>
If mvn install/compile gives any error, delete your m2 directory and try again.
Related
I want to use a scala dependency in a pure Java project. There is no need to write scala in my project but of course I will have to use classes/etc defined in the scala project that I add as a dependency. Want to do this in a intelliJ maven project.
My pom 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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xxx</groupId>
<artifactId>xxxx</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>group ID</groupId>
<artifactId>scala dependancy</artifactId>
</dependency>
</dependencies>
</project>
Although I dont see any errors in pom, intellij is unable to import packages defined in the scala library. Essentially it cant find them.
What am I doing wrong here?
You can do so by adding the following dependency to your pom.xml file:
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- This plugin compiles Scala files -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- This plugin compiles Java files -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- This plugin adds all dependencies to JAR file during 'package' command.
Pay EXTRA attention to the 'mainClass' tag.
You have to set name of class with entry point to program ('main' method) -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>ScalaRunner</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Take a look at this for more information.
I'm using the latest maven 3.3.9 which enforces java 8, and trying to compile a project in java 7 using a java 7 maven toolchain.
As per: The maven guide I've put in the maven toolchain plugin to try and tell it to use java 7 to compile the app. My project setup is as follows:
top_module --> (have put in maven toolchain plugin in this pom.xml)
---submodule1
---submodule2
This is my parent pom.xml:
<?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>
<parent>
<groupId>parent</groupId>
<artifactId>build-base</artifactId>
<version>1.0.17</version>
</parent>
<groupId>top_module</groupId>
<artifactId>top_module</artifactId>
<version>1</version>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
<modules>
<module>submodule1</module>
<module>submodule2</module>
</modules>
<properties>
...
</properties>
<dependencyManagement>
<dependencies>
<dependency>
...
</dependency>
<dependency>
...
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
...
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<!-- Ensure we compile as the correct jdk version -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>1.7</version>
<vendor>sun</vendor>
</jdk>
</toolchains>
</configuration>
</plugin>
<!-- Maven WAR Plugin -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${maven.war.plugin.version}</version>
<inherited>true</inherited>
<configuration>
<archiveClasses>true</archiveClasses>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>enforce</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
...
</project>
The build doesn't run any toolchain related steps and conks out when running mvn clean install due to a plugin being incompatible with java 8, which obviously means the toolchain isn't getting run. Do I need anything else in the pom?
This is my toolchains.xml file in my M2_HOME:
<?xml version="1.0" encoding="UTF8"?>
<toolchains>
<!-- JDK toolchains -->
<toolchain>
<type>jdk</type>
<provides>
<version>1.6</version>
<vendor>sun</vendor>
</provides>
<configuration>
<jdkHome>C:\Java\jdk1.6.0_45</jdkHome>
</configuration>
</toolchain>
<toolchain>
<type>jdk</type>
<provides>
<version>1.7</version>
<vendor>sun</vendor>
</provides>
<configuration>
<jdkHome>C:\Java\jdk1.7.0_79</jdkHome>
</configuration>
</toolchain>
</toolchains>
The problem is simply related that you have defined all plugins in pluginManagement but you need to define them like this:
<build>
<pluginManagement>
<plugins>
<!-- Ensure we compile as the correct jdk version -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>1.1</version>
</plugin>
<!-- Maven WAR Plugin -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${maven.war.plugin.version}</version>
<inherited>true</inherited>
<configuration>
<archiveClasses>true</archiveClasses>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>enforce</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
<configuration>
<toolchains>
<jdk>
<version>1.7</version>
<vendor>sun</vendor>
</jdk>
</toolchains>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
pluginManagement is intended to define versions and default configurations but no binding to the lifeycle which you need to do for the maven-toolchains-plugin. In pluginManagement you should define all plugins which their versions which you are using which means maven-resources-plugin, maven-install-plugin, maven-deploy-plugin, maven-enforcer-plugin etc. This might be a good candidate for a corporate parent pom which defines all those things.
And you are going the best way to separate the JDK which is used by Maven and the JDK which is used by your code.
Apart from that Maven 3.3.9 needs JDK 7 as minimum and not JDK 8
If you just want maven to use the java 7 jdk all the time, the toolchain plugin may be more than you need. it may be enough to set JAVA_HOME
Make sure that JAVA_HOME is set to the location of your JDK, e.g. export JAVA_HOME=/usr/java/jdk1.7.* and that $JAVA_HOME/bin is in your PATH environment variable. ( Or if from eclipse, set it as the workspace default )
If you want to switch jdk from just 1 project, you can also use the compilerVersion tag
https://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html
I transferred a big java project to maven and replaced all the libraries used with maven and I can run debug or start just fine meaning that it works normally but for some reason whenever I try to run maven test or install or anything that tries to compile it using maven it fails.
This is my pom file (I use nexus for third party jars):
<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>pbclient2</groupId>
<artifactId>pbclient2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Name</name>
<description>Description</description>
<dependencies>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
.
.
.
<dependency>
<groupId>mxmlc</groupId>
<artifactId>mxmlc</artifactId>
<version>1.0</version>
<classifier>mxmlc</classifier>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src</directory>
</resource>
</resources>
<sourceDirectory>src</sourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<inherited>true</inherited>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<!-- <plugin> <groupId>com.google.appengine</groupId> <artifactId>appengine-maven-plugin</artifactId>
<version>1.9.32</version> <configuration> <enableJarClasses>false</enableJarClasses>
</configuration> <executions> <execution> <goals> <goal>endpoints_get_discovery_doc</goal>
</goals> </execution> </executions> </plugin> -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<phase>test</phase>
<id>analyze</id>
<goals>
<goal>analyze-only</goal>
</goals>
<configuration>
<failOnWarning>true</failOnWarning>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build></project>
I have tried a lot of plugins and tried deleting the .m2 repository but nothing seems to help.
All the errors I get are
[ERROR] /C:/Users/worx-pc-01/git/PbClient/pbclient2/src/pb/ui/panels/admin/workorders/configuration/namingConvention/GenericNamingConventionTableModel.java:[10,24] package com.pb.hibernate does not exist
or
[ERROR] /C:/Users/worx-pc-01/git/PbClient/pbclient2/src/pb/ui/panels/admin/workorders/configuration/namingConvention/GenericNamingConventionTableModel.java:[192,36] cannot find symbol
symbol: class PbPwoNamingConfiguration
location: class pb.ui.panels.admin.workorders.configuration.namingConvention.GenericNamingConventionTableModel
The package does exist and I don't understand why this won't work like its supposed to.
Am I doing something wrong since I just started using maven.
The error messages suggest to me that either the package com.pb.hibernate doesn't exist in your project (maybe it has been renamed and your IDE didn't update every use properly) or it exists in an external dependency which your IDE has somehow got in its path when running/debugging, but the dependency isn't defined correctly in your pom, and so running mvn clean install fails
I'm using Maven to build my project, but when I run the command mvn clean package deploy, it tries to deploy the artifact twice. I have the build-helper-maven-plugin plugin configured to attach an ear file that I create using a custom plugin.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/${project.artifactId}-${project.version}.ear</file>
<type>ear</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
When I disable build-helper-maven-plugin, the remaining artifact (only the pom) is uploaded only once.
What should I do to let Maven deploy the extra ear file only once?
Erates
EDIT
<?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>my.group.id</groupId>
<artifactId>my.artifact.id</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>My Project</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<scm>
<!-- Config -->
</scm>
<distributionManagement>
<repository>
<!-- Config -->
</repository>
<snapshotRepository>
<!-- Config -->
</snapshotRepository>
</distributionManagement>
<dependencies>
<!-- My Dependencies here -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<includeGroupIds>my.group.ids.that.need.to.be.included</includeGroupIds>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>my.group.id</groupId>
<artifactId>my.custom.plugin</artifactId>
<version>1.0.1</version>
<configuration>
<params>
<!-- My params -->
</params>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>my-custom-goal</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Release Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.4</version>
<configuration>
<goals>clean package deploy</goals>
<tagBase>https://my.tagbase</tagBase>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/${project.artifactId}-${project.version}.ear</file>
<type>ear</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<modules>
<!-- My Modules -->
</modules>
</project>
First you are using module and trying to do weird things in your parent pom (dependency-plugin, build-helper etc.). In a parent there should never be an execution like you have in your pom. You should make the appropriate configuration/execution within the appropriate modules cause this definition will be inherited of all childs.
Would you like to create an ear file? Than you should use packaging ear and your ear file will simply being deployed by using mvn deploy.
Furthermore you seemed to misunderstand the life cycle cause if you call:
mvn clean package deploy
this can be reduced to:
mvn clean deploy
cause the package life cycle is part of deploy so i recommend to read the life cycle information.
I am using maven for configuration of an application consisting of multiple small services. Most of the services developed in java share the same maven configuration, as in the same build lifecycle, some shared resources (like spring AMQP).
So I have organized the shared resources in a SuperPom.
While the shade plugin doesn't really seem to disturb the install process, the antrun plugin of course won't find any of the files it should copy, due to there not being created any jar files by the shade plugin.
As I'd like the configuration of the shade/antrun plugin to be abstracted in the SuperPom, I need to skip the shade/copy goal.
I have tried mvn clean install -Dmaven.shade.skip=true, mvn clean install -Dmaven.copy.skip=true, mvn clean install -Dmaven.shade.shade.skip=true
Here is a small sample for you to play with:
<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>Test</groupId>
<artifactId>SuperTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<log4j.version>1.2.17</log4j.version>
<destination>pleasedeleteme</destination>
<mainpackage>com.uk.cc.it.info.gov.test.xxx</mainpackage>
</properties>
<build>
<plugins>
<plugin>
<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>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${mainpackage}.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${destination}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>
</project>
Did you try setting the phase of maven-shade-plugin to none in the super-pom and then overriding this in the client poms?
So in the parent pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>shade</id>
<phase>none</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<!-- ... -->
</configuration>
</execution>
</executions>
</plugin>
And in the child poms that need it:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<!-- no need to specify version -->
<executions>
<execution>
<id>shade</id>
<phase>package</phase>
<!-- no need to specify configuration -->
</execution>
</executions>
</plugin>
The maven-shade-plugin doesn't have a parameter to skip. Often the shade-plugin isn't there just for fun, so you might wonder if you really want to skip this. If you think it is still valid, you have to create a profile with activation like this:
<activation>
<property>
<name>skipShade</name>
<value>!true</value>
</property>
</activation>
This way it is activated by default, unless you add -DskipShade or -DskipShade=true.
Maven 3.6.1 gives you a new approach.
In the superPom you can define a profile for your shading configuration:
<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>Test</groupId>
<artifactId>SuperTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<log4j.version>1.2.17</log4j.version>
<destination>pleasedeleteme</destination>
<mainpackage>com.uk.cc.it.info.gov.test.xxx</mainpackage>
</properties>
<build>
<plugins>
<plugin>
<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-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${destination}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>shade</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<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>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${mainpackage}.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
In the user's settings.xml under .m2 you can add a profile of the same id to enable the shade profile configuration of your superPom. This gives you the option to simple toggling the shading from inside your IDE like Intellij IDEA (only tested in Intellij).
<settings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<!-- toggle shading from inside Intellij IDEA -->
<profiles>
<profile>
<id>shade</id>
</profile>
</profiles>
<!-- Shade Profile has to be activeProfile to be
able to explicitly disable shading -->
<activeProfiles>
<activeProfile>shade</activeProfile>
</activeProfiles>
</settings>
In the child project you can add a .mvn/maven.config file to your child project template to predefine shading for the project by default. (Requires a CVS template that is used to predefine a company standard.)
The approach using a maven.config is useful if some of your team members do not have the profile in their settings.xml file and you have to take care that shading will be done most of the time.
.mvn/maven.config:
-Pshading
The profile can also be activated by default using jenkinsfile for Jenkins by passing -Pshade. It will overwrite the maven.config setting. To disable use -P!shade
Please note if you are using maven.config file in Intellij (2020.2.2): The .mvn/maven.config file must exists in the subdirectory of the root aggregator pom folder. Building a subproject form the IDE does not respect a .mvn/maven.config file on the subproject level at the moment. Running a mvn command from the command line in the subproject folder will repespect both, the child project .mvn/maven.config and the parent .mvn/maven.config.
Disabling the maven shade plugin worked for me. The build was stock trying to produce the dependency reduced pom file before I disabled the Maven shade plugin.
The skip option was introduced in version 3.3.0 of the shade plugin, so now skipping can be done dynamically using, for example, properties:
<properties>
....
<skipShaded>true</skipShaded>
</properties>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<skip>${skipShaded}</skip>
...
</configuration>
</execution>
</executions>
</plugin>
In the above the default is to skip, and this can be overridden with passing -DskipShaded=false to mvn.