Maven results on Run and Tests Run are not same - maven

I' trying to test 4 scenarios in a feature using the mvn clean test and all the tests are running as expected but the results shows as below
Maven Result
[INFO]   Run 1: PASS
[ERROR]   Run 2: MainRunner.runScenario » NoSuchIdentifiableElement Element fileExplorerButton ...
[INFO]   Run 3: PASS
[ERROR]   Run 4: MainRunner.runScenario » NoSuchIdentifiableElement Element fileExplorerButton ...
[INFO]
[INFO]
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO]
[ERROR] There are test failures.
Runner class
#CucumberOptions(
features = "classpath:cucumber-features/someTest.feature", glue = { "automatedtest.tests.steps",
"autotest.arch.steps" },
plugin = {
"pretty",
"html:target/cucumber-html-report/",
"json:target/cucumber-json-report/report.json", "io.qameta.allure.cucumber6jvm.AllureCucumber6Jvm"
}
)
public class MainRunner extends AbstractTestNGCucumberTests {}
I dont understand why is there a mismatch.
PARENT POM
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>${spring.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies></dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<includes>
<include>**/MainRunner.class</include>
</includes>
<printSummary>true</printSummary>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
POM under src/test/
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<includes>
<include>**/MainRunner.class</include>
</includes>
</configuration>
</plugin>
I tried to add
<forkCount>, <printSummary>,

Related

Java classpath build with "spring-boot-maven-plugin" does not work

Try to build a classpath with jars to invoke my program with java-command
"java -cp %classpath% %mainclass%".
But can't manage to get to it run.
When building the jar with "spring-boot-maven-plugin" I always get an error because mainclass cannot be found.
When building the jar with "maven-jar-plugin/maven-assembly-plugin", the Spring environment is not found.
I have setup a small sample project to test and show. It would be great if someone could give me some help here.
My project looks like this:
mysample-base (has a packaging of "pom" and has module "mysample-frontend")
mysample-frontend (has a packaging of "pom" and has module "mysample-frontend-programs")
mysample-frontend-programs (has a packaging of "jar" and contains the programs).
These are the poms:
mysample-base/pom.xml
<groupId>com.mysamples</groupId>
<artifactId>mySamples-base</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<revision>1.0.0</revision>
<targetJarDir>E:/$SysProg/mySample/RUN/lib</targetJarDir>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
</parent>
<modules>
<module>mySamples-frontend</module>
</modules>
<dependencies>
<!-- ***************************************************************************************************
* Springboot *************************************************************************************************** -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- ***************************************************************************************************
* Database Access *************************************************************************************************** -->
<!-- https://mvnrepository.com/artifact/org.codehaus.mojo/jaxb2-maven-plugin -->
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<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-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${targetJarDir}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
mysample-frontend/pom.xml
<artifactId>mySamples-frontend</artifactId>
<packaging>pom</packaging>
<parent>
<groupId>com.mysamples</groupId>
<artifactId>mySamples-base</artifactId>
<version>1.0.0</version>
</parent>
<modules>
<module>mySamples-frontend-programs</module>
</modules>
mysample-frontend-progams/pom.xml - with "spring-boot-maven-plugin"
<artifactId>mySamples-frontend-programs</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<parent>
<groupId>com.mysamples</groupId>
<artifactId>mySamples-frontend</artifactId>
<version>1.0.0</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.4.RELEASE</version>
<configuration>
<fork>true</fork>
<mainClass>com.mysamples.calling.MainCalling</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
mysample-frontend-progams/pom.xml - with "maven-assembly-plugin"
<artifactId>mySamples-frontend-programs</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<parent>
<groupId>com.mysamples</groupId>
<artifactId>mySamples-frontend</artifactId>
<version>1.0.0</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<archive>
<manifestEntries>
<Build-Version>${project.version}</Build-Version>
<Built-By>${user.name}</Built-By>
<Build-Jdk>${java.version}</Build-Jdk>
<Build-Time>${maven.build.timestamp}</Build-Time>
<Build-Number>${buildNumber.value}</Build-Number>
<Build-YearStarted>2020</Build-YearStarted>
<DeveloperName>Ulrich Schmidt</DeveloperName>
</manifestEntries>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I' m running this command:
cd /D .....
SET CLASSPATH=mySamples-frontend-programs-1.0.0.jar
java -Duser.language=en -cp mySamples-frontend-programs-1.0.0.jar com.mysamples.calling.MainCalling
In case of using "spring-boot-maven-plugin" for building jar, I get this message:
Error: Could not find or load main class com.mysamples.calling.MainCalling
Looking in the jar file shows, that the main-class is stored to "ROOT-INF/classes". In the root-path of the jar I can only find the spring framework.
In case of using "maven-assembly-plugin" for building jar, I get this message:
java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.
at org.springframework.util.Assert.notEmpty(Assert.java:467)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getCandidateConfigurations(AutoConfigurationImportSelector.java:180)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getAutoConfigurationEntry(AutoConfigurationImportSelector.java:123)
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector$AutoConfigurationGroup.process(AutoConfigurationImportSelector.java:434)
at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGrouping.getImports(ConfigurationClassParser.java:878)
at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImports(ConfigurationClassParser.java:808)
at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorHandler.process(ConfigurationClassParser.java:779)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:192)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:319)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:280)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:96)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:707)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:533)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at com.mysamples.calling.MainCalling.main(MainCalling.java:27)
The both of the classes created are:
#ComponentScan({"com.mysamples"})
#SpringBootApplication
public class MainCalling {
private static final Logger LOGGER = LoggerFactory.getLogger(MainCalling.class);
#Autowired
public MainCalling(final ClassToBeCalled toBeCalled) {
toBeCalled.isCalled();
}
public static void main(String[] args) {
try {
SpringApplication.run(MainCalling.class);
} catch (Exception e) {
LOGGER.error("", e);
System.exit(-1);
}
}
and
#Service
public class ClassToBeCalled {
private static final Logger LOGGER = LoggerFactory.getLogger(ClassToBeCalled.class);
public void isCalled() {
LOGGER.info("have been called");
}
}
I think I got it. "spring-boot-maven-plugin" does not allow for the command "java -cp ${classpath} ${chosenMain}". You have to use "java -jar ${classpath}" - the way the jar is created, by only springframework in the rootDir of the jar does not nable for calling directly the designated mainClass. The way how to invoke multiple main-Classes is described in "Running spring boot with multiple main classes"
Thanks to #khmarbaise for the hint. Couldn't believe in the first place, but after some reading, I got, he is right.

Compile errors due to missing queryDSL classes when creating arquillian webArchive with shrinkwrap and MavenImporter

I'm trying to write a simple arquillian test to a large project. There are a bunch of QClasses that are automatically created to query the database but it seems that at the time Shrinkwrap.create() runs, those classes are not created yet and the deploy never completes.
MyTest class:
package pkg.integration.service;
import static org.junit.Assert.assertNotNull;
import javax.inject.Inject;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.resolver.api.maven.archive.importer.MavenImporter;
import org.junit.Test;
import org.junit.runner.RunWith;
import pkg.service.TestService;
#RunWith(Arquillian.class)
public class MyTest {
#Deployment
public static WebArchive getDeploy() {
return ShrinkWrap.create(MavenImporter.class)
.loadPomFromFile("/path/to/pom.xml")
.importBuildOutput()
.as(WebArchive.class);
}
#Inject
private TestService testService;
#Test
public void test() {
assertNotNull(testService);
}
}
Execution stacktrace:
java.lang.RuntimeException: Could not invoke deployment method: public static org.jboss.shrinkwrap.api.spec.WebArchive br.com.company.integration.service.MyTest.getDeploy()
at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.invoke(AnnotationDeploymentScenarioGenerator.java:181)
at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.generateDeployment(AnnotationDeploymentScenarioGenerator.java:103)
at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.generate(AnnotationDeploymentScenarioGenerator.java:64)
at org.jboss.arquillian.container.test.impl.client.deployment.DeploymentGenerator.generateDeployment(DeploymentGenerator.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:103)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:85)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:143)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)
at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
at org.jboss.arquillian.container.test.impl.client.ContainerEventController.execute(ContainerEventController.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:103)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:85)
at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:92)
at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:92)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:143)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)
at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.beforeClass(EventTestRunnerAdaptor.java:87)
at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:202)
at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:431)
at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:55)
at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:219)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:167)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.invoke(AnnotationDeploymentScenarioGenerator.java:177)
... 49 more
[omitted]
symbol: class QConfiguracao
location: package com.company.portal.model, /path/to/src/main/java/pkg/portal/service/UserService.java:[124,38] cannot find symbol
[... A LOT of 'cannot find symbol' errors pointing to QClasses]
[... A LOT of 'cannot find symbol' errors pointing to QClasses]
[... A LOT of 'cannot find symbol' errors pointing to QClasses]
location: package pkg.vo
at org.jboss.shrinkwrap.resolver.impl.maven.archive.packaging.AbstractCompilingProcessor.constructCompilationException(AbstractCompilingProcessor.java:120)
at org.jboss.shrinkwrap.resolver.impl.maven.archive.packaging.AbstractCompilingProcessor.compile(AbstractCompilingProcessor.java:92)
at org.jboss.shrinkwrap.resolver.impl.maven.archive.packaging.WarPackagingProcessor.importBuildOutput(WarPackagingProcessor.java:84)
at org.jboss.shrinkwrap.resolver.impl.maven.archive.packaging.WarPackagingProcessor.importBuildOutput(WarPackagingProcessor.java:50)
at org.jboss.shrinkwrap.resolver.impl.maven.archive.importer.PomEquippedMavenImporterImpl.importBuildOutput(PomEquippedMavenImporterImpl.java:49)
at org.jboss.shrinkwrap.resolver.impl.maven.archive.importer.PomEquippedMavenImporterImpl.importBuildOutput(PomEquippedMavenImporterImpl.java:44)
at pkg.service.MyTest.getDeploy(MyTest.java:27)
... 54 more
Test ignored.
jun 16, 2017 8:32:38 PM org.jboss.arquillian.core.impl.ObserverImpl resolveArguments
ADVERTÊNCIA: Argument 2 for ArquillianServiceDeployer.undeploy is null. It won't be invoked.
Process finished with exit code 255
build>:
<build>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.sql</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources/db</directory>
<targetPath>db</targetPath>
<filtering>false</filtering>
</resource>
</resources>
<filters>
<filter>${basedir}/src/main/resources/filters/${filter.name}.properties</filter>
[filters...]
</filters>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-filtering</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<extensions>false</extensions>
</plugin>
<!-- Compila .jrxml para .jasper -->
<plugin>
<groupId>com.alexnederlof</groupId>
<artifactId>jasperreports-plugin</artifactId>
<dependencies>
<!--Força para ser as mesmas versões de runtime-->
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>${jasperreports.version}</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-fonts</artifactId>
<version>${jasperreports-fonts.version}</version>
</dependency>
</dependencies>
</plugin>
<!-- mvn backupdb:copy backupdb:restore -->
<plugin>
<groupId>com.company</groupId>
<artifactId>backupdb-maven-plugin</artifactId>
<version>0.8.3</version>
<configuration>
<databaseType>postgres</databaseType>
<bucketFolder>${company.db.name}/db</bucketFolder>
<databaseName>${company.db.name}</databaseName>
<postScript>src/test/resources/db/post_restore.sql</postScript>
</configuration>
</plugin>
<plugin>
<groupId>com.company</groupId>
<artifactId>company-jpa-maven-plugin</artifactId>
<version>${company.jpa.version}</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<configuration>
<includes>
<include>**/*Spec.java</include> <!-- Yes, .java extension -->
<include>**/*Test.java</include> <!-- Just in case of having also "normal" JUnit tests -->
</includes>
<argLine>-Xmx256m</argLine>
<properties>
<property>
<name>listener</name>
<value>com.company.testng.ListenerDominio</value>
</property>
</properties>
<threadCount>1</threadCount>
<useUnlimitedThreads>true</useUnlimitedThreads>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${surefire.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>${surefire.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>addTestSources</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.gmaven.runtime</groupId>
<artifactId>gmaven-runtime-2.0</artifactId>
<version>1.5</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.1</version>
</dependency>
</dependencies>
<configuration>
<testSources>
<testSource>
<directory>${project.basedir}/src/test/java</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</testSource>
</testSources>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<versionRange>[1.0-beta-2,)</versionRange>
<goals>
<goal>compile-reports</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<!-- we want to execute specifications -->
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<testSourceDirectory>${project.basedir}/src/test/groovy</testSourceDirectory>
<includes>
<include>**/*Specification*</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>arquillian-wildfly-remote</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- this is required to get test resources filtered properly -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
</pluginManagement>
</build>
dependencyManagement>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-bom</artifactId>
<version>${version.org.jboss.shrinkwrap.resolver}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap</groupId>
<artifactId>shrinkwrap-bom</artifactId>
<version>${version.org.jboss.shrinkwrap}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>${version.org.jboss.arquillian}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-core</artifactId>
<version>${version.org.jboss.arquillian}</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>${version.org.jboss.arquillian}</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-standalone</artifactId>
<version>${version.org.jboss.arquillian}</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.spock</groupId>
<artifactId>arquillian-spock-container</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>company-external-bom</artifactId>
<version>2.0.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>company-parent-test</artifactId>
<version>1.0.0</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>3.0.1.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
So... What am I'm missing?
PS: I'm executing the tests through Intellij. A mvn clean package on terminal gives me a:
[ERROR] /path/to/src/test/java/company/service/MyTest.java:[8,33] error: package org.jboss.arquillian.junit does not exist
[ERROR] /path/to/src/test/java/company/service/MyTest.java:[16,9] error: cannot find symbol
IIRC Maven runner does not honor all plugins but just the common ones. I think that in you case you should use EmbeddedMaven https://github.com/shrinkwrap/resolver#embedded-maven instead of importer.
Yeah, the MavenImporter is probably not the best solution for you - it takes your dependency stack, compiles all classes in src/main/java directory, takes all resources and merges everything in the resulting web-archive. It doesn't take into account any plugin that you use nor additional directories.
On the other hand, EmbeddedMaven builds the whole project, so then you can use an archive that contains all necessary classes/dependencies.
As for the error: package org.jboss.arquillian.junit does not exist it seems that you don't have correct dependencies on your classpath. Please share your <dependencies> you have in your pom.xml file or your dependency tree.

Maven + AspectJ weaving for Java8

I Cannot mvn package with the minimal sample below. Eclipse (Mars.2 Release 4.5.2) compiles and weaves without a problem.
What do I have to do to make it work?
The output:
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # test ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 2 source files to ...\workspace\test\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] .../workspace/test/src/main/java/test/Foo.java:[6,21] cannot find symbol
symbol: method doSomethingInjected()
A sample class:
package test;
public class Foo {
public void bar() {
this.doSomethingInjected();
}
}
Sample interface:
package test;
public interface Injectable { }
aspect:
package test;
public aspect Injection {
declare parents : test..* implements Injectable;
public void Injectable.doSomethingInjected() {
System.out.println("done");
}
}
pom.xml (relevant parts as per aspectj-maven-plugin usage doc)
<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>test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.9</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.9</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Try this, it makes your project compile and run cleanly (I tested it):
<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>de.scrum-master.stackoverflow</groupId>
<artifactId>aspectj-introduce-method</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.source-target.version>1.8</java.source-target.version>
<aspectj.version>1.8.10</aspectj.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>${java.source-target.version}</source>
<target>${java.source-target.version}</target>
<!-- IMPORTANT -->
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.9</version>
<configuration>
<!--<showWeaveInfo>true</showWeaveInfo>-->
<source>${java.source-target.version}</source>
<target>${java.source-target.version}</target>
<Xlint>ignore</Xlint>
<complianceLevel>${java.source-target.version}</complianceLevel>
<encoding>${project.build.sourceEncoding}</encoding>
<!--<verbose>true</verbose>-->
<!--<warn>constructorName,packageDefaultMethod,deprecation,maskedCatchBlocks,unusedLocals,unusedArguments,unusedImport</warn>-->
</configuration>
<executions>
<execution>
<!-- IMPORTANT -->
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>

DefaultChemObjectBuilder ClassNotFoundException occur when running jmh benchmark in terminal Intellij Idea

I can run the project as an application in IntelliJ IDEA by using main method. But when I'm trying to run it using terminal for benchmark, a class not found exception occurs.
public class MyBenchmark {
#Benchmark
public static void sdfIterativeReader() throws ClassNotFoundException, FileNotFoundException {
File sdfFile = new File("molecule.sdf");
IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
IteratingSDFReader reader = new IteratingSDFReader(new FileInputStream(sdfFile),builder);
while (reader.hasNext()) {
IAtomContainer molecule = (IAtomContainer) reader.next();
IMolecularFormula formula = MolecularFormulaManipulator.getMolecularFormula(molecule);
String molecularFromula = MolecularFormulaManipulator.getString(formula);
System.out.println(molecularFromula);
}
}
}
I used the command: mvn clean install then project is building successfully. When I run the command:
java -jar target/benchmarks.jar
it gives the following error:
Here, I have attached my 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>org.chemid</groupId>
<artifactId>chemid-benchmark</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>JMH benchmark sample: Java</name>
<prerequisites>
<maven>3.0</maven>
</prerequisites>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.openjdk.jmh/jmh-generator-annprocess -->
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>cdk</groupId>
<artifactId>cdk</artifactId>
<version>1.5.13</version>
<scope>system</scope>
<systemPath>${cdk.lib}/cdk-1.5.13 .jar</systemPath>
</dependency>
<dependency>
<groupId>net.sourceforge.streamsupport</groupId>
<artifactId>streamsupport</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>org.openscience.cdk</groupId>
<artifactId>cdk-io</artifactId>
<version>1.5.13</version>
</dependency>
<dependency>
<groupId>org.openscience.cdk</groupId>
<artifactId>cdk</artifactId>
<version>1.5.13</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.openscience.cdk</groupId>
<artifactId>cdk-core</artifactId>
<version>1.5.13</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<jmh.version>1.6.3</jmh.version>
<javac.target>1.8</javac.target>
<uberjar.name>benchmarks</uberjar.name>
<cdk.lib>${basedir}/libs</cdk.lib>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerVersion>${javac.target}</compilerVersion>
<source>${javac.target}</source>
<target>${javac.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${uberjar.name}</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.openjdk.jmh.Main</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<!--
Shading signed JARs will fail without this.
http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar
-->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.1</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
</plugin>
</plugins>
</pluginManagement>
</build>
Add to file MANIFEST.MF this line:
Class-Path: lib/cdk-1.5.13.jar
Or run you benchmark thought class with main method:
java -cp path/to/cdk/lib/cdk-1.5.13.jar:. com.your.main.ClassName
For more info read answers from this discussion.
And also this answer to understand system scope of Maven dependency that you've chose for cdk-1.5.13.jar.

maven surefire test plugin runs tests even if they are excluded:

i exclude all tests in plugin except my test suite:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.11</version>
<configuration>
<!--
<testFailureIgnore>true</testFailureIgnore>
<skipTests>true</skipTests>
-->
<parallel>both</parallel>
<threadCount>10</threadCount>
<forkMode>once</forkMode>
<configuration>
<excludes>
<exclude>**/Test*.java</exclude>
<exclude>**/*Test.java</exclude>
<exclude>**/*TestCase.java</exclude>
</excludes>
<includes>
<include>ru.csbi.registry.CategorizedTestsSuite.java</include>
</includes>
</configuration>
<!--
<configuration>
<groups>ru.csbi.registry.IntegrationTestsNotRequiringContainerCategory</groups>
<groups>ru.csbi.registry.UnitTestsCategory</groups>
</configuration>
-->
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.12</version>
</dependency>
</dependencies>
</plugin>
but all tests are executed.
Even if i delete my the only include in config it still runs all tests:
<configuration>
<excludes>
<exclude>**/Test*.java</exclude>
<exclude>**/*Test.java</exclude>
<exclude>**/*TestCase.java</exclude>
</excludes>
<!--
<includes>
<include>ru.csbi.registry.CategorizedTestsSuite.java</include>
</includes>
-->
</configuration>
Here is the logs:
------------------------------------------------------- T E S T S
------------------------------------------------------- Concurrency config is parallel='both',perCoreThreadCount=true,
threadCount=10, useUnlimitedThreads=false
Running javalangtests.AnnotationTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Running ru.csbi.registry.services.JdbcServiceTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Running ru.csbi.registry.services.reflection.ClassServiceTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Running ru.csbi.registry.services.reflection.FieldServiceTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Running
ru.csbi.registry.services.reflection.hibernate.relation.RelationServiceTest
Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016
sec
Effective pom:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<configuration>
<includes>
<include>ru.csbi.registry.CategorizedTestsSuite.java</include>
</includes>
</configuration>
</configuration>
</execution>
</executions>
<configuration>
<configuration>
<includes>
<include>ru.csbi.registry.CategorizedTestsSuite.java</include>
</includes>
</configuration>
</configuration>
</plugin>
You need to remove configuration block from configuration block.
Like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.11</version>
<configuration>
<!--
<testFailureIgnore>true</testFailureIgnore>
<skipTests>true</skipTests>
-->
<parallel>both</parallel>
<threadCount>10</threadCount>
<forkMode>once</forkMode>
<excludes>
<exclude>**/Test*.java</exclude>
<exclude>**/*Test.java</exclude>
<exclude>**/*TestCase.java</exclude>
</excludes>
<includes>
<include>ru.csbi.registry.CategorizedTestsSuite.java</include>
</includes>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.12</version>
</dependency>
</dependencies>
</plugin>
Nested configuration element makes no sense. As well as package name in your include (ru.csbi.registry.CategorizedTestsSuite.java).

Resources