spock trying to use wrong groovy version - maven

This is my new pom, simplified, I created new project and added just minimum to be able to run spock
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xyz</groupId>
<artifactId>xxxxx</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>scenarios</name>
<description>desc</description>
<packaging>pom</packaging>
<parent>
<groupId>yyyr</groupId>
<artifactId>bbb</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.3-groovy-2.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.5.7</version>
<type>pom</type>
</dependency>
</dependencies>
but still I cannot run test, now I get
Information:Groovyc: While compiling tests of model:java.lang.NoClassDefFoundError: org/codehaus/groovy/ast/MethodCallTransformation needed for org.codehaus.groovy.macro.transform.MacroTransformation
at org.jetbrains.jps.incremental.groovy.JointCompilationClassLoader._defineClass(JointCompilationClassLoader.java:41)
at com.intellij.util.lang.UrlClassLoader.defineClass(UrlClassLoader.java:376)
....

The above POM (the one I edited in the question) worked, in include spock and all dependencies

Related

Vert.x annotation processor problem with module-info.java

I'm trying to create a new project in Java that is composed by several modules (following the Java Modules concept introduced on Java 9). In one of those modules, I'm trying to use vert.x codegen to generate a service that will be exposed to the other modules.
Now that problem is that when I try to compile the service module I got the following error:
module-info.java:[5,22] module not found: io.vertx.codegen.
For your reference, I will put my module configuration (as stated on module-info.java) and my POM file.
Module-info.java:
module mo.com.test.daomodule {
requires io.vertx.core;
requires io.vertx.client.sql.mssql;
requires io.vertx.client.sql;
requires io.vertx.codegen;
requires io.vertx.serviceproxy;
requires org.apache.logging.log4j.core;
requires org.apache.logging.log4j;
exports mo.com.test.dao.db.service;
exports mo.com.test.dao.db;
}
My pom:
<?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>mo.com.test</groupId>
<artifactId>MainProject</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<properties>
<vertx.version>4.2.1</vertx.version>
<jdbc.version>9.4.0.jre11</jdbc.version>
<log4j2api.version>2.14.1</log4j2api.version>
<log4j2core.version>2.14.1</log4j2core.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-stack-depchain</artifactId>
<version>${vertx.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-json-schema</artifactId>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-jdbc-client</artifactId>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-mssql-client</artifactId>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-codegen</artifactId>
<version>${vertx.version}</version>
<classifier>processor</classifier>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-service-proxy</artifactId>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>${jdbc.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2api.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2core.version}</version>
<type>jar</type>
</dependency>
</dependencies>
<groupId>mo.com.test</groupId>
<artifactId>daomodule</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>daomodule</name>
</project>
By checking above, I have added the necessary imports in the POM file and add include the vert.x modules as required in the module-info.java.
No my question is, what can I do to solve this compilation problem? Is there anything missing on my POM or my module-info.java?

Added maven dependencies is giving

After adding Maven dependencies I'm getting a compilation error.
<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</groupId>
<artifactId>Sample1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Sample1</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.15</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.41.2</version>
</dependency>
</dependencies>
</project>
The console shows a warning:
Compiler Error Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project Sample1: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
Looks like your IDE is pointed to JRE. Add JDK path in your IDE
For Eclipse try these steps:
Windows --> perfernces --> java--> installed JREs.
Add your JDK and click on the newly added JDK
for reference

To remove extra dependencies inherited from spring-boot-starter-parent

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
When spring-boot-starter-parent is used as parent, then it includes many unnecessary dependencies. Like in my case it fetches the dependencies for
(spring-mobile-device , spring-social-facebook , spring-social-linkedin , org.apache.activemq ) which i don't want.
If I open my effective POM(with get's auto created) , it's contains hell lot of dependencies which i don't want.
Is there any way to remove the unnecessary dependencies which are not used in the project? Is there a tool to identify such dependencies?
Any help is appreciated :)
Thanks
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>demo</groupId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>demo</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
<relativePath />
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId>
<version>2.2.4</version>$NO-MVN-MAN-VER$ </dependency> -->
<!-- <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-client</artifactId>
<version>1.17.1</version> </dependency> -->
<!-- <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId>
<version>4.4.1</version>$NO-MVN-MAN-VER$ </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId> <version>4.4.1</version> </dependency> -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<!-- <dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId>
<version>2.8</version> </dependency> -->
<!-- <dependency> <groupId>com.rabbitmq</groupId> <artifactId>amqp-client</artifactId>
<version>3.5.4</version> </dependency> -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>4.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-common</artifactId>
<version>4.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
<version>4.5.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>demo.Application</start-class>
<java.version>1.7</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<artifactId>DEMO</artifactId>
spring-boot-starter-parent doesn't declare any dependencies. However, via spring-boot-dependencies, it does provide dependency management for a wide-range of potential dependencies.
From Maven's documentation:
The dependency management section is a mechanism for centralizing dependency information. When you have a set of projects that inherits a common parent it's possible to put all information about the dependency in the common POM and have simpler references to the artifacts in the child POMs
The references to artifacts can be simpler as, thanks to the dependency management, there's no need to declare a version. For example:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<dependency>
<dependencies>
If you don't specify a version, Maven will use the version that's configured in the dependency management.
Only when you add an entry in your pom's <dependencies> section will your project actually have that dependency and Maven will download it as part of the build.

Use Spring boot only for development

I am kind of newbie to maven configuration and using spring-boot .
I want to use spring boot but I only want it to be active for development, when I deploy the artifact to other environments like QA or Production I want to generate a war, and I dont want to have any spring-boot dependecy.
How could I accomplish this ?
This is my current 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xxxxx</groupId>
<artifactId>xxxxx</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>xxxxxxx</name>
<url>http://maven.apache.org</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>
<java.version>1.8</java.version>
<spring.version>4.2.0.RELEASE</spring.version>
<jackson.version>2.6.0</jackson.version>
<slf4j.version>1.7.12</slf4j.version>
</properties>
<!--
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
</parent>
-->
<dependencies>
<!-- Spring dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!--
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb-api.version}</version>
<scope>runtime</scope>
</dependency>
-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
</build>
</project>
I have heard a bit about maven profiles , but I am not sure how it works, and if it is the best solutions for this use case. Basically what I want, It is to introduce spring-boot dependencies only for development stage and keep the current ones for production and qa stages.
Thanks!
You really can't have a dynamic parent. However, just setting spring boot as parent will not bring you any dependencies, it will only provide you access to the properties and dependencyManagement and will help you manage dependency versions easier.

Jongo Maven dependency causing run time issue

I have a Maven project where I am using the Jongo dependency with the following POM.
<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>mytracker</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>mytracker</name>
<url>http://maven.apache.org</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>
</dependency>
<dependency>
<groupId>com.yammer.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>0.6.2</version>
</dependency>
<dependency>
<groupId>net.vz.mongodb.jackson</groupId>
<artifactId>mongo-jackson-mapper</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>org.jongo</groupId>
<artifactId>jongo</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.joda</groupId>
<artifactId>joda-money</artifactId>
<version>0.10.0</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.jersey-test-framework</groupId>
<artifactId>jersey-test-framework-core</artifactId>
<version>1.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.test.framework</groupId>
<artifactId>jersey-test-framework</artifactId>
<version>1.0.3.1</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
</dependencies>
</project>
Now when I run my Main class , I get the following error in eclipse , although the project is built successfully using Maven , this error shows up when I run the Main class. I am using JDK 1.7 ,any ideas ?
Exception in thread "main" java.lang.VerifyError: (class: org/jongo/marshall/jackson/configuration/AbstractMappingBuilder, method: <init> signature: ()V) Incompatible argument to function
at org.jongo.Jongo.<init>(Jongo.java:32)
at com.mycompany.mytracker.CashbackService.run(CashbackService.java:44)
at com.mycompany.mytracker.CashbackService.run(CashbackService.java:18)
at com.yammer.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:38)
at com.yammer.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:58)
at com.yammer.dropwizard.cli.Cli.run(Cli.java:53)
at com.yammer.dropwizard.Service.run(Service.java:61)
at com.mycompany.mytracker.CashbackService.main(CashbackService.java:22)
I removed the following dependency and it solved my problem.
<dependency>
<groupId>net.vz.mongodb.jackson</groupId>
<artifactId>mongo-jackson-mapper</artifactId>
<version>1.4.2</version>
</dependency>

Resources