Java: package cucumber.api.junit does not exist - java

I've been trying to get this to work.
I would like set up a test runner class like so
However I get this error:
Error:(3, 26) java: package cucumber.api.junit does not exist
Error:(10, 10) java: cannot find symbol
symbol: class Cucumber
The class looks like:
package nl.prvgld.sigma.aanvraagtitels.testutil;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
public class RunFeature {
}
Pom.xml looks like:
<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">
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<modelVersion>4.0.0</modelVersion>
<groupId>nl.prvgld.sigma.aanvraagtitels</groupId>
<artifactId>Aanvraagtitels</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Aanvraagtitels</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java8</artifactId>
<version>1.2.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-core -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>
<dependency>
<groupId>com.smartbear.readyapi.testserver.cucumber</groupId>
<artifactId>testserver-cucumber-core</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
All classes are somewhere under the Test folder.
I've been lookin at some related questions here and tried the solutions like removing test from Pom, and making sure I have junit, cucumber-junit, cucumber-java8 and cucumber-core in the Pom.
I am using Intellij.
Any help in the right direction is highly appreciated!
Cheers!

I don't know if you already resolved your issue but you can quickly fix it by removing the scope tags from your pom.xml file. Do this action for all dependencies that you are facing issues and should work fine.
Cheers,
HH

By inspection, everything looks good. But obviously, it doesn't work as you expect.
Do you get the same error when compiling with IDEA and compiling with Maven?
To get started, I would clone a getting started project from the Cucumber team and get it working. It is much easier to later extend it to contain the things you need. Clone https://github.com/cucumber/cucumber-java-skeleton and build it using Maven with
mvn clean install
It is expected to work out of the box.
With a working solution, take small steps toward the project you actually would like to have.

Change the imports.
instead of: import cucumber.api.junit.Cucumber;
use import io.cucumber.junit.Cucumber;

Related

module-info when one of my external libraries doesn't have a module-info

I am a beginner in Java coding, I am teaching myself JavaFX and making a project that uses JPA through Hibernate (I have no knowledge on Spring yet).
The problem I find myself having is that an essential external library doesn't have a module-info for me to refer to in my project.
I can have either JavaFX or mysql-connector-java working, but not both at the same time.
The connector I am using is: https://mvnrepository.com/artifact/mysql/mysql-connector-java version 8.0.19
When I exclude my module-info my JPA works, when I use my module-info my FX works
I asked my teacher for help but he doesn't seem to have an idea yet on how I can use my JavaFX and JPA in the same project. Does anyone have a good suggestion on how I can fix this issue?
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>
<groupId>com.tumblr.calscodingcorner</groupId>
<artifactId>dnd5e_database_maker</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>com.tumblr.calscodingcorner.application.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.19</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.12.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx</artifactId>
<version>11</version>
<type>pom</type>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-controls -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
</dependencies>
My module.info
module dnd5e.database.maker {
requires javafx.controls;
requires java.persistence;
requires mysql.connector.java;
exports com.tumblr.calscodingcorner.application;}
Thanks in advance for any advice
Answering the title:
module-info when one of my external libraries doesn't have a module-info
You need to require (in module-info.java) the automatic module name corresponding to the name of the dependency jar (without the version), or to the Automatic-Module-Name declared in the jar's MANIFEST (if exists). Then maven will automatically add the jar to --module-path.
If you don't require the jar inside module-info, it will be added to --classpath in which case it will become part of the unnamed module and won't be visible by your module (only by automatic modules).
You can add -X to maven to see which dependencies are added to -classpath and which to --module-path
See the spec
[...] A named module cannot, in fact, even declare a dependence upon the unnamed module. This restriction is intentional, since allowing named modules to depend upon the arbitrary content of the class path would make reliable configuration impossible

How to set up TestNG+Jenkins

I'm using Jenkins to run some testNG test, when the build is finished i get the following message at the end:
[INFO] Build failures were ignored.
TestNG Reports Processing: START
Looking for TestNG results report in workspace using pattern: **/test-output/testng-result.xml
Did not find any matching files.
Finished: SUCCESS
I looked at the workspace in Jenkins and there is no folder named test-output, the question here is, how do I tell jenkins to create the folder with the results in there?
Here is my pom.xml if needed:
<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.barco.automation</groupId>
<artifactId>barcoAutomation</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>barcoAutomation</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>
<!-- added -->
</properties>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.42.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.10-FINAL</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.10-FINAL</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</dependency>
</dependencies>
<build>
<finalName>My Automated tests</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
Thanks
you need to add post-build action in jenkins to add relative path of the testng-result.xml which can be found in your workspace.
I will recommend you to use HTML Report Publisher Plugin in Jenkins addon and configure your reports as below. This will allow you to view the report for every build. Through this you will be able to archive all your testNG reports build wise and it can be seen on the Job level as well. Once you are installing this plugin, configure your job and add a POST-BUILD-STEP (to enable the HTML REPORT PUBLISHER) and follow the location setting for testNG reports. Please refer to the screenshot below and let me know in case of any questions. Hope this helps!
Typically, your TestNG reports generated here :
<Jenkins-Location>\jobs\<JOB_NAME>\workspace\target\html

cucumber junit runner java.lang.NoSuchMethodError:

Trying to implement cucumber to do some automated tests. jUnit tests. I've created 2 files and edited pom.xml that comes with maven project to add dependencies. Content is shown below. The first of two files are cucumber .feature files, which is a gherkin of plain language. The other is CukesRunner.java
When I run my tests using Project -> Run as ... -> Maven test it works as expected.
However when I ran the CukesRunner.java file using Eclipse the Eclipse JUnit GUI, I get an error:
java.lang.NoSuchMethodError: org.junit.runner.Description.createSuiteDescription(Ljava/lang/String;Ljava/io/Serializable;[Ljava/lang/annotation/Annotation;)Lorg/junit/runner/Description;
at cucumber.runtime.junit.FeatureRunner.getDescription(FeatureRunner.java:43)
at cucumber.api.junit.Cucumber.describeChild(Cucumber.java:77)
at cucumber.api.junit.Cucumber.describeChild(Cucumber.java:41)
at org.junit.runners.ParentRunner.getDescription(ParentRunner.java:226)
...
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>com.bdd</groupId>
<artifactId>airportparking</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>airportparking</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.1.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.1.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.rubiconproject.oss</groupId>
<artifactId>jchronic</artifactId>
<version>0.2.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
CukesRunner.java:
package com.bdd.airportparking;
import cucumber.api.junit.*;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#Cucumber.Options(
format={"pretty", "html:target/cucumber"},
features="src/test/resources"
)
public class CukesRunner {
}
ValetParking.feature:
Feature: Valet Parking
As a traveler
In order to determine where to park my car
I want to know the cost of valet parking
Scenario: Calculate valet parking cost for half an hour
When I park my car in the Valet Parking Lot for 30 minutes
Then I will have to pay $12
Output when running CukesRunner.java as a Junit Test:
java.lang.NoSuchMethodError: org.junit.runner.Description.createSuiteDescription(Ljava/lang/String;Ljava/io/Serializable;[Ljava/lang/annotation/Annotation;)Lorg/junit/runner/Description;
at cucumber.runtime.junit.FeatureRunner.getDescription(FeatureRunner.java:43)
at cucumber.api.junit.Cucumber.describeChild(Cucumber.java:77)
at cucumber.api.junit.Cucumber.describeChild(Cucumber.java:41)
at org.junit.runners.ParentRunner.getDescription(ParentRunner.java:226)
at org.junit.runner.Runner.testCount(Runner.java:38)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.countTestCases(JUnit4TestClassReference.java:30)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.countTests(RemoteTestRunner.java:487)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:455)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
How I structured my project in eclipse:
http://postimg.org/image/vf6tlw7el/full/
Updating your junit version and maybe also your surefire plugin will fix this problem.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
For surefire:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
</plugin>
</plugins>
</build>
I had the same issue and got fixed once I configured the latest version. The issue was on junit version 4.10. the latest version from 4.11 works good
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
Different story but same issue... developing a Jenkins plugin, using gradle, had the latest junit:junit:4.12 library on my classpath...
The issue was being caused by the junit:junit-dep:4.10 library, "aka"...
<dependency>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
After explicitly removing it from my configuration classpath, I no longer have the issue.
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.mkolisnyk</groupId>
<artifactId>cucumber-reports</artifactId>
<version>0.0.11</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Werror</compilerArgument>
</configuration>
</plugin>
</plugins>
</build>
I faced the same issue and i found that i have configured both junit 4.10, and 4.11 in my build path, Adhering to junit 11, resolved the issue.
Faced same issue and is resolved by using the JUnit version to 4.11 or higher. Ref: https://groups.google.com/forum/#!topic/cukes/et3rd_0LVRU
Make sure you use the correct JUnit version in your POM.xml.
Change it to latest from 4.10 to 4.11 it works.
I have updated my junit driver from 4.9 to 4.11; it is absolutely a junit driver problem, so just update it, and you will get it.

Maven null dependency and multiple annotations on this line

Something has gone wrong with my pom and I have a blank dependency and artifactId in the xml but get the same error whether I delete the tags or not.
I am using eclipse with m2eclipse installed in my home folder on Linux Mint 14 with maven version 'Apache Maven 2.2.1 (rdebian-8)' installed
Here is the 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>TransferHandler</groupId>
<artifactId>TransferHandler</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.4.6-rc1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-vfs2</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.49</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.2</version>
<classifier>ftp</classifier>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<artifactId></artifactId>
</dependency>
</dependencies>
</project>
There are three error messages displayed:
On line1:
Multiple annotations found at this line:
- null (org.apache.maven.plugins:maven-resources-plugin:2.5:resources:default-resources:process-resources)
- null (org.apache.maven.plugins:maven-resources-plugin:2.5:testResources:default-testResources:process-test-
resources)
On line70:
Multiple annotations found at this line:
- Project build error: 'dependencies.dependency.groupId' for null::jar is
missing.
- Project build error: 'dependencies.dependency.version' for null::jar is
missing.
On line 71:
Project build error: 'dependencies.dependency.artifactId' for null::jar is missing.
It seems like the one on line 70 with the empty tags is the root cause (excerpt below) but I'm not sure.
<dependency>
<artifactId></artifactId>
</dependency>
Even if I delete the empty tags from the xml and refresh maven and the project the error remains. On my Dependencies tab I see a jar with a '?' next to it but can't delete it and in my Dependency Hierachy tab I see a ' : [compile]' jar but can delete or exclude it.
How can I remove this ghost/null jar?
Try This Header
<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">
Good Luck !
I found a way around the problem using git but was not able to solve it directly by removing the offending packages.
The work-around was to shutdown eclipse, remove the pom and then use git to discard changes in the working directory. Commands:
rm pom.xml
git checkout -- pom.xml
Then the pom should reappear returned to its state at the last commit (which luckily for me was before this error arose). Not a very satisfying answer but at least it worked. If anyone posts an answer and explanation to the heart of the real problem (ie why can't I remove a null package and how did it get there in the first place) I would still be happy to accept it.

Add my own bundle sources to pax-exam when building with pax-maven-plugin

I'm trying to build my OSGI bundle with pax-maven-build and in the same time test it with pax-exam. It have some bundle in provision than I can test with the following pax-exam test configuration:
#RunWith(JUnit4TestRunner.class)
#ExamReactorStrategy(AllConfinedStagedReactorFactory.class)
public class OSGILoaderTest {
#Inject
protected BundleContext bundleContext;
#Configuration
public Option[] config() throws MalformedURLException {
String projectRoot = // a path to my project
return options(
junitBundles(),
equinox(),
bundle(projectRoot + "libs/org.eclipse.core.variables_3.2.500.v20110511.jar"),
bundle(projectRoot + "libs/org.eclipse.core.contenttype_3.4.100.v20110423-0524.jar"),
bundle(projectRoot + "libs/org.eclipse.core.expressions_3.4.300.v20110228.jar"),
// etc...
);
}
#Test
public void getBundleContext() throws RodinDBException {
IRodinDB rodinDB = RodinCore.getRodinDB();
assertNotNull(rodinDB);
}
}
Here, I can see I can access to the IRodinDB instance from a jar I have provisonned.
Now I have code my own bundle, which is going to use all the jar provisionned. But I cannot even test my own code, for instance:
#Test
public void checkAccessToRodinDbTest() {
VTGService service = null;
assertTrue(true);
}
give an error at compilation time:
[ERROR] Failed to execute goal org.ops4j:maven-pax-plugin:1.5:testCompile (default-testCompile) : Compilation failure
[ERROR] cannot find symbol
[ERROR] symbol : class VTGService
It seems test compilation cannot see 'src/main/java', contrarly as expected by the default behavior of maven-compiler-plugin. But in my case, you can see than maven does not use the compiler plugin but instead maven-pax-plugin.
The question is: how can i test my own bundle with pax-exam ?
update1
It seems that this is a problem with recent version of maven-pax-plugin, as the basic example available in ops4j pax maven plugin (in section Using the Pax Plugin inside a POM) seems to suffer of the same problem.
update2
As requested by Dmytro, this is the pom.xml of my bundle:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<relativePath>../poms/compiled/</relativePath>
<groupId>fr.xlim.ssd.vtg.build</groupId>
<artifactId>compiled-bundle-settings</artifactId>
<version>0.1-SNAPSHOT</version>
</parent>
<properties>
<bundle.symbolicName>fr.xlim.ssd.vtg.bundle</bundle.symbolicName>
<bundle.namespace>fr.xlim.ssd.vtg.bundle</bundle.namespace>
</properties>
<modelVersion>4.0.0</modelVersion>
<groupId>fr.xlim.ssd.vtg</groupId>
<artifactId>fr.xlim.ssd.vtg.bundle</artifactId>
<version>0.1-SNAPSHOT</version>
<name>${bundle.symbolicName}</name>
<packaging>bundle</packaging>
<dependencies>
<dependency>
<type>pom</type>
<groupId>${project.parent.groupId}</groupId>
<artifactId>provision</artifactId>
<optional>true</optional>
</dependency>
<!-- not needed as equinox bundle are available in provision -->
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi_R4_core</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi_R4_compendium</artifactId>
<optional>true</optional>
</dependency-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam</artifactId>
<version>2.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-junit4</artifactId>
<version>2.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-inject</artifactId>
<version>2.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.url</groupId>
<artifactId>pax-url-mvn</artifactId>
<version>1.3.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-container-native</artifactId>
<version>2.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-link-mvn</artifactId>
<version>2.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
I am not sure it is the most elegant solution, but I created a new maven project when I can import my own bundle like in the source code of my question.
Is there an elegant way to add my own java sources directly as new bundle for test in the same Maven project ? It could be not possible (as the bundle assembly operation is done after the compilation and tests)...
I use the following setup to provision the bundle under test. When configuring the test, I provision the bundle using the reference-protocol (this is a non-standard feature of Equinox and Felix, see here):
#Configuration
public Option[] config() {
return options(
bundle("reference:file:target/classes"),
junitBundles(),
felix()
);
}
The test-cases also run when you specify knopplerfish() as the environment. I guess that is because the URL is resolved by Pax Exam, and not by the OSGi-runtime. I use the maven-bundle-plugin to build my bundles. To make this work as expected, you have to add the following configuration:
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<executions>
<!-- This execution makes sure that the manifest is available
when the tests are executed -->
<execution>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Otherwise the manifest will not be available when the tests are run, since by default it is generated during the package-phase.
I hope I did not forget anything - please let me know if it worked for you!
Check PaxExam docs how to configure your Maven POM with PaxExam.
Samples here

Categories

Resources