How to use JPA-Entities as a dependency with maven - java

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>

Related

How to deploy de-Lombok-ed sources with maven

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>

Maven generated static metamodels in Hibernate 5.2 not recognized by DAO classes

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.

Adobe flex migration error defaults.css expected

I am having an issue migrating from Adobe Flex 3.3.0.4852 to 4.5.1.21328
Applying the same configuration I had it set up it throws a exception executing flexmojos-maven-plugin
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.2.0</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>compile-swf</goal>
</goals>
</execution>
</executions>
<configuration>
<moduleFiles>
<module>APP_MIGRATED.mxml</module>
</moduleFiles>
<locales>
<param>en_US</param>
</locales>
<services>${basedir}/src/main/resources/services-config.xml</services>
<contextRoot>root</contextRoot>
<keepAllTypeSelectors>true</keepAllTypeSelectors>
<output>${basedir}/target/APP_MIGRATED.swf</output>
<targetPlayer>9.0.0</targetPlayer>
</configuration>
</plugin>
The error is triying to compile the source it trows the next error:
[ERROR]
C:\m2_repo_clean\com\adobe\flex\framework\advancedgrids\4.5.1.21328\advancedgrids-4.5.1.21328.swc$defaults.css:[13,-1]
{ expected. [ERROR]
C:\m2_repo_clean\com\adobe\flex\framework\charts\4.5.1.21328\charts-4.5.1.21328.swc$defaults.css:[13,-1]
{ expected. [ERROR]
C:\m2_repo_clean\com\adobe\flex\framework\charts\4.5.1.21328\charts-4.5.1.21328.swc$defaults.css:[14,-1]
{ expected. [ERROR]
C:\m2_repo_clean\com\adobe\flex\framework\charts\4.5.1.21328\charts-4.5.1.21328.swc$defaults.css:[108,-1]
Unexpected character: D. [ERROR]
C:\m2_repo_clean\com\adobe\flex\framework\charts\4.5.1.21328\charts-4.5.1.21328.swc$defaults.css:[112,-1]
{ expected. [ERROR]
C:\m2_repo_clean\com\adobe\flex\framework\framework\4.5.1.21328\framework-4.5.1.21328.swc$defaults.css:[15,-1]
{ expected. [ERROR]
C:\m2_repo_clean\com\adobe\flex\framework\mx\4.5.1.21328\mx-4.5.1.21328.swc$defaults.css:[15,-1]
{ expected. [ERROR]
C:\m2_repo_clean\com\adobe\flex\framework\spark\4.5.1.21328\spark-4.5.1.21328.swc$defaults.css:[15,-1]
{ expected. [WARNING]
C:\Workspaces\aa_Branches\aa_jdk8_upgrade\flex\src\main\flexapp\APP_MIGRATED.mxml:[0,-1]
CSS selector condition type is not supported: ':normalWithPrompt'
[WARNING]
C:\Workspaces\aa_Branches\aa_jdk8_upgrade\flex\src\main\flexapp\APP_MIGRATED.mxml:[0,-1]
CSS selector condition type is not supported: ':disabledWithPrompt'
This is my full pom configuration
<parent>
<artifactId>app-migrated</artifactId>
<groupId>com.appmigrated</groupId>
<version>1.7-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>flex</artifactId>
<packaging>pom</packaging>
<name>Flex</name>
<build>
<finalName>APP_MIGRATED</finalName>
<sourceDirectory>src/main/flexapp</sourceDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
</resource>
<resource>
<directory>${basedir}/target/generated-resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>${flex-mojos.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>compile-swf</goal>
</goals>
</execution>
</executions>
<configuration>
<moduleFiles>
<module>APP_MIGRATED.mxml</module>
</moduleFiles>
<locales>
<param>en_US</param>
</locales>
<services>${basedir}/src/main/resources/services-config.xml</services>
<contextRoot>root</contextRoot>
<keepAllTypeSelectors>true</keepAllTypeSelectors>
<output>${basedir}/target/APP_MIGRATED.swf</output>
<targetPlayer>9.0.0</targetPlayer>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<goals>
<goal>wrapper</goal>
</goals>
<phase>generate-resources</phase>
</execution>
</executions>
<configuration>
<ignoreVersionIssues>true</ignoreVersionIssues>
<htmlName>APP_MIGRATED</htmlName>
<outputDirectory>${project.build.directory}/html-wrapper</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-config</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<outputDirectory>${project.build.directory}/generated-resources</outputDirectory>
<includeArtifacIds>APP_MIGRATED</includeArtifacIds>
<includeGroupIds>${project.groupId}</includeGroupIds>
<excludeTransitive>true</excludeTransitive>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make.html-bundle</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptors>
<descriptor>src/main/assembly/html-bundle.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make.resources</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptors>
<descriptor>src/main/assembly/resources.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<flex.sdk.version>4.5.1.21328</flex.sdk.version>
<flex-mojos.version>4.0-RC2</flex-mojos.version>
</properties>
<dependencies>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>flex-framework</artifactId>
<version>${flex.sdk.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.adobe.cairngorm</groupId>
<artifactId>cairngorm</artifactId>
<version>2.2.1</version>
<type>swc</type>
</dependency>
</dependencies>
I know maybe there is can be another errors after this one, but this is the one which concerns me more.
Greetings,
try flexmojos 7 :
<properties>
<flexmojos.version>7.0.1</flexmojos.version>
<flex.version>4.13.0.20140701</flex.version>
<flash.version>16.0</flash.version>
</properties>
plugin look like this
<plugins>
<plugin>
<groupId>net.flexmojos.oss</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>${flexmojos.version}</version>
<extensions>true</extensions>
<configuration>
<sourceFile>APP_MIGRATED.mxml</sourceFile>
<compilerWarnings>
<warn-no-constructor>false</warn-no-constructor>
</compilerWarnings>
</configuration>
<dependencies>
<!-- This handles a bug in maven which causes problems with flex resources -->
<dependency>
<groupId>net.flexmojos.oss</groupId>
<artifactId>flexmojos-threadlocaltoolkit-wrapper</artifactId>
<version>${flexmojos.version}</version>
</dependency>
<!-- Without this FM will use the compiler configured in its master
pom, which will result in version conflicts -->
<dependency>
<groupId>org.apache.flex</groupId>
<artifactId>compiler</artifactId>
<version>${flex.version}</version>
<type>pom</type>
</dependency>
</dependencies>
</plugin>

maven - why is my pom.xml NOT removing META-INF/*.SF, META-INF/*.DSA and META-INF/*.RSA?

On my pom.xml I have the following <plugin> section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<excludeScope>system</excludeScope>
<excludes>META-INF/*.SF</excludes>
<excludes>META-INF/*.DSA</excludes>
<excludes>META-INF/*.RSA</excludes>
<excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
<outputDirectory>${project.build.directory}/classes/lib/</outputDirectory>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
But, whenever I build the project with a mvn clean install -U, some .SF, .DSA and .RSA are copied to the built jar file and I need to remove them manually.
How to correct this?
The correct usage of tag <excludes> is following:
<excludes>META-INF/*.SF,META-INF/*.DSA,META-INF/*.RSA</excludes>

jaxb circular dependency maven compile error

I've code which generates classes and these are referenced in main package
I'm using jaxb2 plugin and running on commandline. my code creates generate-sources ,but compile fails saying symbol can't find.
can somebody help me what's going wrong. here is my plugin in pom.xml
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaIncludes>
<schemaInclude>*-1.0.xsd</schemaInclude>
</schemaIncludes>
<bindingIncludes>
<bindingInclude>*bindings-1.0.xjb</bindingInclude>
</bindingIncludes>
</configuration>
</plugin>
</plugins>

Categories