Is it possible to use mapstruct together with jpastreamer? - spring

i'm writing a spring-boot project in which i'm using mapstruct. Code that mapstruct generates is located in target/generated-sources/annotations.
I would like to use also jpastreamer library. I used build-helper-maven-plugin to generate metamodel.
The problem i'm facing is that this library also generates metamodel into the same directory, so only the code generated by mapstruct is available.
Here is my code:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/annotations</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>16</release>
<source>16</source>
<target>16</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.4.2.Final</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>

I do not know which library jpastream is. However, if it is an annotation processor then you should include that as part of the maven-compiler-plugin annotationProcessorPaths. That way all the annotation processors will be invoked in the same time and the code will be appropriately generated.
The fact that you only see the code generated by MapStruct in the target/generated-sources/annotations folder is due to the fact that the maven-compiler-plugin deletes everything from that folder before running the annotation processors.
If that jpastream library is not an annotation processor but something else, then you should generate its classes in another locaton not target/generated-sources/annotations, but rather target/generated-sources/jpastream

Related

Problem using CriteriaBuilder's isMember method with Kotlin

When using the isMember method of CriteriaBuilder with Kotlin in my application it gives me the following error in the following line:
I've been researching and they always use that form to add a predicate to filter when they need to filter on a list of entity elements.
Do you know what could be happening?
Thank you.
Content_-like classes are generated from corresponding #Entity classes. You need to enable plugin that makes this job done during build. With Maven it could be done like following:
<build>
...
<plugins>
...
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>3.1.0</version>
<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>${hibernate.version}</version>
</dependency>
</dependencies>
</plugin>
...
</plugins>
...
</build>
After rebuild Content_ (and all similar classes) should appear on classpath

Maven just run Integration Tests when call mvn install

Well, I'm using Spring Boot 2.4.0 with Surefire and Failsafe, so the following plugins:
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
<!-- other annotation processors -->
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
I have Unit tests (*Test.java) and integration tests (*IT.java). But running mvn clean package just run unit tests, I need run mvn clean instasll to run integration tests + unit tests.
Any tips? This is correct?

Tycho copy-dependencies do not include plugin dependencies

For one plugin in my tycho reactor I would like to copy a "pure-maven" dependency and its transitive ones in a folder named "lib/".
Currently if I use the copy-dependencies goal from maven-dependency-plugin, my dependency is correctly copied but the "plugin-dependencies" resolved by tycho are also copied, and I don't want those.
Any suggestion to achieve this goal ? I'm currently using the following code snippet
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>${maven.groupid}</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>process-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Any suggestions are welcome.
Following this discussion on Eclipse forums it seems that we can tell maven to only include dependencies coming from the current pom.xml file using a combination of excludeScope and includeScope tags.
This updated XML snippet does the job as expected
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>${maven.groupid}</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>process-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<!-- The lines below are aimed at telling maven NOT TO COPY tycho dependencies. Do not remove those! -->
<!-- See: https://dev.eclipse.org/mhonarc/lists/tycho-user/msg05080.html -->
<excludeScope>system</excludeScope>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Shade Plugin Harcording Dependency For Excluded Artifact also

I have the following shade plugin config :
<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>
<createSourcesJar>false</createSourcesJar>
<keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<artifactSet>
<includes>
<include>XXXX:AAAA-common</include
</includes>
<excludes>
<exclude>XXXX:client</exclude>
</excludes>
</artifactSet>
<finalName>${project.artifactId}-${project.version}</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I see that the XXXX:client is being excluded from the maven dependency, but in that pom that gets generated, I see that the dependency is getting hard coded with the version
<dependency>
<groupId>XXXX</groupId>
<artifactId>client</artifactId>
<version>1.2.3</version>
<scope>compile</scope>
</dependency>
Is there a way we can remove the dependency entirely, or just remove the hardcoded version ?
On further analysis, I found that their is no way we can remove the hardcoded version. An alternative which you can try is maven-assembly plugin but it provides very little flexibility.

maven-failsafe-plugin not seeing my tests (seleniumHQ)

i'm writing tests via selenium web driver here's my code :
Pom.xml
<project>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.24.1</version>
</dependency>
</dependencies>
<build>
<finalName>SeleniumebDriverProject</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.11</version>
<configuration>
<!-- Skip the normal tests, we'll run them in the integration-test phase-->
<skip>false</skip>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
My test class named GoogleTest.java.
after reading this post : failsafe plugin won't run on one project but will run on another -- why?
I changed the name of my class so it's:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.11</version>
<configuration>
<!-- Skip the normal tests, we'll run them in the integration-test phase-->
<skip>false</skip>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
<executions>
</plugin>
But the problem persist.
The goal of the maven-failsafe-plugin is named integration-test instead of test. Furthermore if you changed your naming convention to the convention of maven-failsafe-plugin than you don't need any configuration which includes etc. files. Just use the defaults.
Furthermore i assume you have started running the integration tests via:
mvn verify

Resources