Hello dear stackoverflowers
Dealing with the Cucumber docs and a lot of "googleizing", I still stay stuck with the Maven, Java, Junit5 and Cucumber and some java modules integration (with a JDK18).
Having a very simple java desktop application (yes, I know this odd), I am trying to get my cucumber's features executed from maven (with the help of surefire.
Here is my simplified pom.xml file.
I think I have no more issues on the Java Module side as there is no 'illegal access" error.
But having an (I hope) clear configuration, I am not able to get the feature tests executed, nothing happened at 'surefire' side:
--- maven-surefire-plugin:3.0.0-M7:test (default-test) # usecasetdd ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
And the Cucumber "bootstraper":
package com.demodemo.core.tests;
//...
#Suite
#IncludeEngines("cucumber")
#SelectClasspathResource("com/demodemo/core/tests/features")
#ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.demodemo.core.tests")
class GameBDDTests {
}
And the structure of my project is as below:
Maybe I've done a basic error, but even digging the web, I've not found it... Is there a way to make that work, or no chance to achieve that?
Could you help ?
Anyway, thanks for any help you will be able to offer on this not so simple topic.
Very best regards,
McG.
You should define only the following as dependencies and don't use properties because all the dependencies of junit jupiter are defined via the bom file..
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<scope>test</scope>
</dependency>
There is no need for supplemental version properties or alike. The cucumber parts are also defined via cucumber bom.
Related
I have always gotten my dependencies from http://mvnrepository.com. Has worked every time. But I can't seem to get wss4j working. My POM is like this:
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.wss4j</groupId>
<artifactId>wss4j</artifactId>
<version>2.1.3</version>
</dependency>
</dependencies>
I can get the Spring just fine, but I keep getting the "Can't find dependency" error. I even use the -U option and I get this:
Downloading: http://repo1.maven.org/maven2/org/org/apache/wss4j/wss4j/2.1.3/wss4j-2.1.3.jar
Downloading: https://repo.maven.apache.org/maven2/org/apache/wss4j/wss4j/2.1.3/wss4j-2.1.3.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.411s
[INFO] Finished at: Sat Oct 10 14:31:51 EDT 2015
[INFO] Final Memory: 9M/303M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project crypt.lib: Could not resolve dependencies for project mmaceachran:crypt.lib:jar:0.0.1-SNAPSHOT: Could not find artifact org.apache.wss4j:wss4j:jar:2.1.3 in mvnrepository (http://repo1.maven.org/maven2/org/) -> [Help 1]
But there is is downloading!!! What am I doing wrong?
UPDATE:
I used the -e option and I see that it can't find the artifact:
Caused by: org.sonatype.aether.transfer.ArtifactNotFoundException: Could not find artifact org.apache.wss4j:wss4j:jar:2.1.3 in central (https://repo.maven.apache.org/maven2)
but it is clearly there: http://repo1.maven.org/maven2/org/apache/wss4j/wss4j/2.1.3/
Starting from WSS4J 2.x, the org.apache.wss4j/wss4j module is just used as part of the website generation. The dependency you probably want is org.apache.wss4j/wss4j-ws-security-dom.
Colm.
No, it isn't there: The artifact you declared in your pom has no <type>. i.e.: by default, Maven assumes a jar type. Look in URL you posted and realise there is no .jar artifact.
Surely you need to specify a type=pom.
I recently added this dependency to pom.xml
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.4.0</version>
</dependency>
My builds are failing in jenkins with the following error message:
[WARNING] Found duplicate resources in [org.codehaus.groovy:groovy:2.3.7,org.codehaus.groovy:groovy-json:2.3.7,org.codehaus.groovy:groovy-xml:2.3.7] :
[WARNING] META-INF/groovy-release-info.properties
[JENKINS] Archiving disabled
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5:37.485s
[INFO] Finished at: Mon Mar 09 10:10:49 PDT 2015
[INFO] Final Memory: 46M/381M
[INFO] ------------------------------------------------------------------------
[JENKINS] Archiving disabled
Waiting for Jenkins to finish collecting data
[ERROR] Failed to execute goal com.ning.maven.plugins:maven-duplicate-finder-plugin:1.0.4:check (default) on project LightmileTest: Found duplicate classes/resources -> [Help 1]
Background/Details
I had a similar issue and this threw me for a loop for a while and I started to question my maven knowledge and did some digging. If you want to learn more about duplicate finder, you can read the readme on their github: https://github.com/ning/maven-duplicate-finder-plugin
For the project I was on, I determined I could do excludes in the dependencies or add exceptions to the duplicate finder. I saw both in my project and wondered when it was appropriate to do which.
The message from the plugin helps identify where duplication resides. You'll normally see this when you try to add new dependencies. When you see that, there are two options, either exclude things from the dependencies, or create exceptions in your com.ning.maven.plugins:duplicate-finder-maven-plugin configuration.
Summary / Conclusion
Adding an exception, just ignores the problem. So the cleaner way is add the excludes in the dependencies. This way you get exactly what you expect/desire. Furthermore, going down the exception route would just add a ton of extra work that isn't really useful. So the intent of the plugin is to help you identify duplications, then try to handle them via excludes in the dependencies.
Example of How to Do Exclude
In your example/case, one of the following should work for you:
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.4.0</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-json</artifactId>
</exclusion>
</exclusions>
</dependency>
or
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.4.0</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
</exclusion>
</exclusions>
</dependency>
It is likely that your new dependency is failing on this test your are doing via Maven (duplicate-finder-plugin). Run the manual check from command line (on the level of the POM file) to find out what are the offending classes:
mvn com.ning.maven.plugins:duplicate-finder-maven-plugin:1.0.4:check
Then you can either remove the dependency or configure the Maven plugin to ignore these. (config here)
dependency:analyze-duplicate Analyzes the and tags in the pom.xml and determines the duplicate declared dependencies.
mvn dependency:analyze-duplicate
What you can do is to follow the rule of scope, meaning that, separate dependencies according to their scopes, such as in your case, rest assured used for testing, why not to put it under the scope of a test:
<scope>test</scope>
Secondary, what I usually do is executing exactly same commands from Jenkins on my local machine and usually it does help, from you error log I think it is not rest assured related, so please try to run MVN goal which is on Jenkins side locally and make sure you have the same error. If not, it can be a different configuration of maven for example via settings.xml in Jenkins machine.
Use to avoid the duplicate finder.
I'm developing a GWT application. It's using RPC to collect information from an internal system. It does so by using a library jar, lets call it alpha.jar. We are using this jar in many application so it works fine, and btw its built with ANT, outside eclipse.
Some classes in alpha.jar references LOG4J2 and also lots of other external jars, so when we run an application we pass a classpath to all those, and everything works out fine. Please note that this is not a simple beginners problem. The alpha.jar is working as it should, including calls to Log4J.
The problem:
In Eclipse, I have this GWT application project and also the Alpha.jar project (with source code of course). The server part needs to instatiate alpha objects and communicate to the alpha system.
When do this in GWT by adding a build-path-reference to the Alpha project, my GWT app runs fine.
When I instead of the project reference include (in war/WEB-INF/lib) the alpha.jar and runs the app, I get the error in the title the first time I instantiate a class from alpha.jar.
There are no peculiarities in how the alpha.jar is built, so basically it should be the same thing as the project in eclipse, right?
Note the following:
*) The alpha.jar's dependent jars are also in war/WEB-INF/lib. log4j2-core, log4j-api as well as a bunch of others (apache common for example)
*) If I remove the alpha.jar (and the code that calls it) and instead just add code that called LOG4J2, that code also works fine!
How come I get this weird error when using the JAR?? Note also the NoClassDefFoundError, its not the more common ClassNotFoundException. Pls see What causes and what are the differences between NoClassDefFoundError and ClassNotFoundException?
If you need more info let me know.
org.apache.log4j.LogManager is a class from log4j 1.2 (not log4j2).
Therefore, one of your web app jars must be referencing it. The culprit should be visible in the stack trace.
Depending upon your circumstances, you may want to just add a log4j 1.2 jar to the web app as the two versions are completely independent of each other.
If you have use log4j 2 please do not forget to name your log4j2.xml instead of log4j.xml
as refered before:
org.apache.log4j.LogManager is a class from log4j 1.2 (not log4j2).
this problem meets when you combine use log4j 1.2 and log4j 2.x, maybe. so you have to add bridge api to you project.
this is a Migrating problem.
Log4j – Migrating from Log4j 1.x - Apache Log4j 2
add those to you pom.xml
<log4j2.version>2.7</log4j2.version>
<disruptor.version>3.3.6</disruptor.version>
<!--log4j2 dependencies -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>${disruptor.version}</version>
</dependency>
then, you could use mvn dependency:resolve to see no log4j 1.2
[INFO] The following files have been resolved:
[INFO] org.springframework.data:spring-data-redis:jar:1.7.2.RELEASE:compile
[INFO] org.apache.logging.log4j:log4j-api:jar:2.7:compile
[INFO] org.apache.logging.log4j:log4j-slf4j-impl:jar:2.7:compile
[INFO] com.lmax:disruptor:jar:3.3.6:compile
[INFO] org.apache.logging.log4j:log4j-1.2-api:jar:2.7:compile
[INFO] javax.mail:mail:jar:1.4.5:compile
[INFO] org.springframework:spring-tx:jar:4.3.1.RELEASE:compile
[INFO] org.apache.logging.log4j:log4j-core:jar:2.7:compile
[INFO] org.apache.logging.log4j:log4j-jcl:jar:2.7:compile
[INFO] javax.activation:activation:jar:1.1:compile
[INFO] org.springframework:spring-beans:jar:4.3.1.RELEASE:compile
[INFO] org.springframework:spring-web:jar:4.3.1.RELEASE:compile
[INFO] org.springframework:spring-webmvc:jar:4.3.1.RELEASE:compile
[INFO] org.springframework:spring-oxm:jar:4.2.6.RELEASE:compile
[INFO] org.springframework:spring-jdbc:jar:4.3.1.RELEASE:compile
[INFO] com.alibaba:fastjson:jar:1.2.4:compile
[INFO] mysql:mysql-connector-java:jar:5.1.21:compile
[INFO] org.apache.tomcat:tomcat-servlet-api:jar:7.0.54:provided
[INFO] org.slf4j:slf4j-api:jar:1.7.21:compile
[INFO] org.springframework:spring-context-support:jar:4.3.1.RELEASE:compile
[INFO] commons-beanutils:commons-beanutils:jar:1.8.3:compile
[INFO] org.springframework:spring-context:jar:4.3.1.RELEASE:compile
[INFO] org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] redis.clients:jedis:jar:2.8.1:compile
[INFO] org.springframework:spring-expression:jar:4.3.1.RELEASE:compile
[INFO] org.springframework.data:spring-data-commons:jar:1.12.2.RELEASE:compile
[INFO] org.springframework.data:spring-data-keyvalue:jar:1.1.2.RELEASE:compile
[INFO] junit:junit:jar:4.12:test
[INFO] org.springframework:spring-core:jar:4.3.1.RELEASE:compile
[INFO] commons-logging:commons-logging:jar:1.2:compile
[INFO] org.springframework:spring-aop:jar:4.3.1.RELEASE:compile
[INFO] org.apache.commons:commons-pool2:jar:2.4.2:compile
[INFO] org.slf4j:jcl-over-slf4j:jar:1.7.21:runtime
refers:
Log4j 1.x Adaptor – Log4j 1.2 Bridge - Apache Log4j 1.x Compatibility API
Log4j Commons Logging Adaptor – Commons Logging Bridge - Apache Log4j Commons Logging Bridge
SLF4J Binding Using Log4j – Log4j 2 SLF4J Binding - Apache Log4j SLF4J Binding
I have a maven project that uses Vert.x library - http://vertx.io/ (but I doubt this has any meaning).
When I try run my app by using vert.x command:
vertx runzip target/service-1.0.0-mod.zip -conf config.json
I'm getting following stacktrace:
Exception in Java verticle
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.mycompany.myproject.vertx.Verticle.createConfig(Verticle.java:116)
...
Caused by: java.lang.NoSuchMethodError: org.joda.time.format.DateTimeFormatter.withZoneUTC()Lorg/joda/time/format/DateTimeFormatter;
at com.mycompany.myproject.mypackage.dao.MyDAO.<clinit>(MyDAO.java:30)
...
JodaTime part of pom.xml:
<dependencies>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
I tried running:
mvn dependency:tree -Dverbose -Dincludes=joda-time
to see if an old version of JodaTime library is loaded as a dependency but all looks OK:
[INFO] --- maven-dependency-plugin:2.7:tree (default-cli) # matching-service ---
[INFO] com.mycompany.myproject:service:jar:1.0.0
[INFO] \- joda-time:joda-time:jar:2.3:compile
It looks like you compiled your MyDAO against a different version of JodaTime than you use when running it.
I.e. there must be two different joda-time jars in your workspace and a static block in MyDAO calling withZoneUTC - unless you only posted half the stack trace and the problem is in a compiled class from the vertx project. In that case you need to get the joda version that vertx was compiled for.
I can't get Intellij Idea 13.0 to compile my code against ASM 5.0.3
I have a multi-module Maven project. It compiles and installs successfully.
Apparently com.google.findbugs:findbugs has a dependency on asm:asm:3.3 and I want to use org.ow2.asm:asm:5.0.3 to manipulate some bytecode.
So in the parent pom.xml I exclude the asm:asm:3.3 dependencies from the classpath. This works fine when I run mvn install from the command line.
I can't get the Build -> Make Project menu selection to work in Intellij Idea.
Here is the relevant parts of my pom.xml files.
parent.pom
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>5.0.3</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-tree</artifactId>
<version>5.0.3</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-util</artifactId>
<version>5.0.3</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
<version>5.0.3</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>findbugs</artifactId>
<version>2.0.3</version>
<exclusions>
<exclusion>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
<exclusion>
<groupId>asm</groupId>
<artifactId>asm-commons</artifactId>
</exclusion>
<exclusion>
<groupId>asm</groupId>
<artifactId>asm-tree</artifactId>
</exclusion>
</exclusions>
</dependency>
Here is the code that is failing
18 public static void main(final String[] args) throws IOException
19 {
20 final InputStream is = NotEmptyTest.class.getResourceAsStream("/com/vertigrated/annotation/NotEmptyTest.class");
21 final ClassReader cr = new ClassReader(is);
22 final ClassNode cn = new ClassNode();
23 cr.accept(cn, 0);
24 for (final MethodNode mn : cn.methods)
25 {
26 - 38 snipped for brevity
39 }
40 }
41 }
Here is the error message:
Information:Using javac 1.7.0_25 to compile java sources
Information:java: Errors occurred while compiling module 'tests'
Information:Compilation completed with 1 error and 2 warnings in 2 sec
Information:1 error
Information:2 warnings
/<path to my source code>/NotEmptyTest.java
Error:Error:line (24)java: incompatible types
required: org.objectweb.asm.tree.MethodNode
found: java.lang.Object
Warning:Warning:java: /<path to my project>//NotEmptyTest.java uses unchecked or unsafe operations.
Warning:Warning:java: Recompile with -Xlint:unchecked for details.
As you can see in the screen capture, it reports the correct version of the libraries in the Javadoc but the AutoComplete shows the old 3.3 non-typesafe return value of List instead of List<MethodNode>:
(source: vertigrated.com)
Here is what Maven knows, which is correct:
[INFO] --- maven-dependency-plugin:2.8:list (default-cli) # tests ---
[INFO]
[INFO] The following files have been resolved:
[INFO] com.google.code.findbugs:bcel:jar:2.0.1:compile
[INFO] junit:junit:jar:4.11:test
[INFO] xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] com.apple:AppleJavaExtensions:jar:1.4:compile
[INFO] javax.inject:javax.inject:jar:1:compile
[INFO] jaxen:jaxen:jar:1.1.6:compile
[INFO] org.ow2.asm:asm-util:jar:5.0.3:compile
[INFO] com.google.inject:guice:jar:3.0:compile
[INFO] dom4j:dom4j:jar:1.6.1:compile
[INFO] com.google.code.findbugs:jFormatString:jar:2.0.1:compile
[INFO] net.jcip:jcip-annotations:jar:1.0:compile
[INFO] org.ow2.asm:asm-tree:jar:5.0.3:compile
[INFO] commons-lang:commons-lang:jar:2.6:compile
[INFO] com.google.code.findbugs:jsr305:jar:2.0.1:compile
[INFO] org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] aopalliance:aopalliance:jar:1.0:compile
[INFO] com.google.code.findbugs:findbugs:jar:2.0.3:compile
[INFO] org.ow2.asm:asm-commons:jar:5.0.3:compile
[INFO] org.ow2.asm:asm:jar:5.0.3:compile
How do I get Intellij Idea to use the correct dependency internally?
It looks like you end up having asm-5.0.3.jar in your compilation class path in IntelliJ IDEA.
This JAR is optimized for minimal size by stripping every bit of it that could be stripped, including the generic signatures (that's how a List<MethodNode> becomes a List, which is effectively List<Object> in your case).
To make sure this is the case, try replacing the dependencies on asm, asm-tree etc by asm-debug-all. The JAR you get will be bigger, but the project should compile now.
Next question is how this compiles in mvn, but fails in IntelliJ IDEA. You can see the class path in the "Project Structure" dialog under "Modules", on the "Dependencies" tab. Maybe the class path was not imported correctly in IntelliJ (in that case, report to IntelliJ IDEA's issue tracker, you'll probably get some help rather soon).