I use Lombok in my library's code and want to use delombok'ed sources when deploying library JAR with sources to maven repository.
How to configure Maven to achieve this?
Update: Most likely, you don't need to deploy delombok'ed sources (check comments below this question for details)
Include following plugins into pom.xml's build/plugins section:
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>1.18.12.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>delombok</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDirectory>src/main/java</sourceDirectory>
<outputDirectory>${project.build.directory}/delombok</outputDirectory>
<addOutputDirectory>false</addOutputDirectory>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-to-lombok-build</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<outputDirectory>${project.build.directory}/delombok</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>generate-delomboked-sources-jar</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<jar
destfile="${project.build.directory}/${project.build.finalName}-sources.jar"
basedir="${project.build.directory}/delombok"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>attach-source-jar</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/${project.build.finalName}-sources.jar</file>
<type>jar</type>
<classifier>sources</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
Related
I am getting this error while uploading the test package on AWS farm. i.e.:
There was a problem processing your file. We could not find a *-tests.jar file in the *root* of your test package.
However, jars are available in the zip file. I have set up my code as per the given instructions in https://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-appium.html
Below are the plugins which I have used in POM.xml :
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</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>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>zip-with-dependencies</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/zip.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Any help is much appreciated.
I got in a multimodule-maven-project an entities project in which there are some Entity and DAO classes. Also there are some integration-tests which I'd like to seperate in an own project called entities-IT.
Now I've put the entities-project as an dependency to the entites-IT-project but if I run the build there occurs an error message like this:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project entities-IT: Compilation failure
[ERROR] /some/path/to/project/entities-IT/src/it/java/com/example/persistence/dao/ExampleDaoIT.java:[25,38] cannot access com.example.persistence.ExampleEntity
[ERROR] bad class file: /some/path/to/project/persistence/ExampleEntity.class
[ERROR] illegal start of class file
[ERROR] Please remove or make sure it appears in the correct subdirectory of the classpath.
This is strange because in the target folder there are all of mentioned .class files and the folderstructure is also correct.
Is there anything to take notice if using Entities as a dependency in another project?
In the pom.xml of the entities-project there is some code-generation going on:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArguments>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.2.4</version>
<executions>
<execution>
<id>process</id>
<configuration>
<outputDirectory>${project.build.directory}/generated-sources/metamodel</outputDirectory>
<compilerArguments>
-Aeclipselink.persistencexml=${project.basedir}/src/main/java/META-INF/persistence.xml
</compilerArguments>
<processors>
<processor>org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor
</processor>
</processors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
and then I have the dependency set in the entities-IT-project:
<dependency>
<groupId>example</groupId>
<artifactId>entities</artifactId>
<version>${parent.version}</version>
</dependency>
and run the tests with the failsafe-plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-integration-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/it/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-integration-test-resources</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/it/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
I have successfully generated metamodels and all metamodel classes are outputted in target/annotations directory.
But my problem is that my other classes such as DAOImpl doesn't recognize these metamodel generated classes. Any help please?
Here is how I generate metamodels using my maven project's pom.xml file:
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>4.3.4.Final</version>
</dependency>
</dependencies>
</plugin>
Check do you have set this:
<plugin> <!--Compiler instructions to generate model, add to sources.-->
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</compilerArguments>
</configuration>
</plugin>
<plugin><!--path were to generate model, add to -->
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<!-- source output directory -->
<outputDirectory>target/metamodel</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/metamodel</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
I think main problem is that folder where you generated classes isn't linked to project sources. You should tell your project that this directory is source folder or generate everything under src directory.
I have tow maven projects resources-win and main-exec.I try to copy a dll file from a folder win of resources-win and copy it to target/classes, then i moved to the project number 2 main-exec and i try to copy a file 2 witch is in src/main/shcemas and the dll file of resources-win and paste them into target classes of the project resources-win
Here is the bloc of code whitch helps to copy a file to target of resources-win:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources01</id>
<phase>process-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<encoding>UTF-8</encoding>
<resources>
<resource>
<directory>${basedir}/src/main/win</directory>
<includes>
<include>**/*.dll</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Here is a part of pom.xml of the project main-exec:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-libraries</id>
<phase>generate-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<!-- win32 -->
<artifactItem>
<groupId>com.resources-win</groupId>
<artifactId>ressources-win</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>pom</type>
<destFileName>xdol.dll</destFileName>
<outputDirectory>${project.build.directory}/temp/schemas</outputDirectory>
</artifactItem>
</artifactItems>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
I did like that by using an xsd file by adding to pom.xml of resources-win:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources-xsd</id>
<phase>process-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<encoding>UTF-8</encoding>
<resources>
<resource>
<directory>${basedir}/src/main/schemas</directory>
<includes>
<include>**/*.xsd</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.outputDirectory}/titi.xsd</file>
<type>xsd</type>
<classifier>titi</classifier>
</artifact>
<artifact>
<file>${project.build.outputDirectory}/toto.xsd</file>
<type>xsd</type>
<classifier>toto</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
Then into the pom.xml of main-exec i added:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-libraries</id>
<phase>generate-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>groupId of resources-win</groupId>
<artifactId>artifactId of resources-win</artifactId>
<version>${resources-win.version}</version>
<type>xsd</type>
<classifier>toto</classifier>
<destFileName>toto.xsd</destFileName>
<outputDirectory>${project.build.directory}/tmp/schemas</outputDirectory>
</artifactItem>
</artifactItems>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
I added also the the pom.xml of main-exec the dependency of resources-win.
I have a mixed Scala/Java project that doesn't compile well.
The problem arises when Java code is trying to call Scala code in the same package.
Of course, I have the standard layout:
src/main/java
src/main/scala
src/test/java
src/test/scala
I've looked at other similar Stackoverflow questions but this question is a little outdated. This other question doesn't help either.
I have also followed the scala-maven-plugin documentation page.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.1.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I have tried unsuccessfully to follow this blog post.
IDEA project with Scala plugin imported from the pom.xml can compile and run my project successfully.
What is the right way of doing it?
Does the Java code gets compiled twice? First by the Scala plugin and the by the Java plugin?.
Here is a working example of 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>
<groupId>stackoverflow</groupId>
<artifactId>q24448582</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<scala.version>2.10.3</scala.version>
</properties>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
<phase>compile</phase>
</execution>
<execution>
<id>test-compile</id>
<goals>
<goal>testCompile</goal>
</goals>
<phase>test-compile</phase>
</execution>
<execution>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Problem 1
At first I thought the problem was due to using a modern version of the maven-compiler-plugin. I was using version 3.0 instead of 2.0.2.
The solution has been:
- Remove the maven-compiler-plugin
- Add this setting: incremental
Finally my pom.xml is this:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.1.6</version>
<configuration>
<recompileMode>incremental</recompileMode>
<args>
<arg>-deprecation</arg>
<arg>-explaintypes</arg>
<arg>-target:jvm-1.7</arg>
</args>
</configuration>
<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>add-source</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
Problem 2
Another problem I was experiencing is this:
<dependencies>
<dependency>
<groupId>org.json4s</groupId>
<artifactId>json4s-native_${scala.version}</artifactId>
<version>3.2.9</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}.4</version>
</dependency>
</dependencies>
<properties>
<scala.version>2.10</scala.version>
</properties>
This make this solved problem arise:
https://issues.scala-lang.org/browse/SI-5733
Probably it was using an old version of the Scala compiler.
The solution has been to rename scala.version to scala.major, as this property has a special meaning.
In order to get the scala-maven-plugin to respect Java 1.8, but still allow mixed compilation of java and scala, we use this:
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<recompileMode>incremental</recompileMode>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
...
I add blow code at pom.xml file <build> block and working good!
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- SCALA AND JAVA MIX COMPILATION -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile</id>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<artifactSet>
<includes>
<include>*:*</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${project.artifactId}-shaded-${project.version}</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
...
</pluginManagement>
<resources>
...
</resources>
</build>