This is the base class of our unit tests:
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration("/spring/test-context.xml")
public abstract class BaseUnitTest {}
All unit tests extend this class.
When I run the tests locally in eclipse (using Run As > Unit Test) , the tests run in about 5 seconds since the same context is shared by all tests and it is loaded only once.
However, when I run them using the mvn test target it takes about 5 minutes. After looking at the logs, I see that the application context is being loaded for every test.
It takes the same time (5 mins) when we run it on our Jenkins CI server.
Not sure what's going on. In spring docs, it states that the appContext should be reused even with maven, but thats not the case here.
Any help would be appreciated.
UPDATE :
I ran mvn with debug flags on and I see that a new JVM is spawned for each test:
Forking command line: cmd.exe /X /C "java -Xverify:none -jar S:\git\picaxo21\picaxo\picaxoService\target\surefire\surefirebooter8169952914558366417.jar S:\git\picaxo21\picaxo\picaxoService\target\surefire\surefire8550033206398936560tmp S:\git\picaxo21\picaxo\picaxoService\target\surefire\surefire_05655453605766528120tmp"
Forking command line: cmd.exe /X /C "java -Xverify:none -jar S:\git\picaxo21\picaxo\picaxoService\target\surefire\surefirebooter4002024477779069323.jar S:\git\picaxo21\picaxo\picaxoService\target\surefire\surefire6735432532690834115tmp S:\git\picaxo21\picaxo\picaxoService\target\surefire\surefire_17783676008756503456tmp"
Forking command line: cmd.exe /X /C "java -Xverify:none -jar S:\git\picaxo21\picaxo\picaxoService\target\surefire\ 7874269889863176184.jar S:\git\picaxo21\picaxo\picaxoService\target\surefire\surefire2050758518148174678tmp S:\git\picaxo21\picaxo\picaxoService\target\surefire\surefire_27591156970671336255tmp"
I am using forkCount=1 and reuseForks=true so I am not sure why this is happening. any clues?
Parent 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
.....
</parent>
<groupId>...</groupId>
<artifactId>picaxo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>.....</name>
<description>Build All Modules</description>
<modules>
<module>picaxoService</module>
</modules>
<scm>
....
</scm>
<properties>
<pmd.include.tests>true</pmd.include.tests>
<findbugs.plugin.version>3.0.0</findbugs.plugin.version>
<fb.threshold>Low</fb.threshold>
<fb.includeTests>true</fb.includeTests>
<fb.effort>Max</fb.effort>
<fb.failOnError>false</fb.failOnError>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<skipTests>true</skipTests>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<skipTests>${skipTests}</skipTests>
<reuseForks>true</reuseForks>
<forkCount>1</forkCount>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>test</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</build>
Found the problem.
Apparently forkMode for surefire plugin was defaulting to pertest hence was spawning a new JVM for each test. Explicitly Setting it to once in the plugin configuration solved the issue.
Related
I tried to work on some AWS S3 implementations and wanted to start off with the provided examples of the AWS Toolkit for Eclipse.
I created the project as following:
Project Configuration
Then right afterwards i get an error in the pom.xml right at line 1 and 13.
<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.amazonaws</groupId>
<artifactId>samples</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.497</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>amazon-kinesis-client</artifactId>
<version>1.2.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Failure to transfer com.amazonaws:aws-java-sdk-swf-libraries:jar:1.11.22 from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the
update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact com.amazonaws:aws-java-sdk-swf-libraries:jar:1.11.22 from/to central (https://
repo.maven.apache.org/maven2): The operation was cancelled. org.eclipse.aether.transfer.ArtifactTransferException: Failure to transfer com.amazonaws:aws-java-sdk-swf-libraries:jar:1.11.22 from
https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error:
Could not transfer artifact com.amazonaws:aws-java-sdk-swf-libraries:jar:1.11.22 from/to central (https://repo.maven.apache.org/maven2): The operation was cancelled. at
org.eclipse.aether.internal.impl.DefaultUpdateCheckManager.newException(DefaultUpdateCheckManager.java:240) at
org.eclipse.aether.internal.impl.DefaultUpdateCheckManager.checkArtifact(DefaultUpdateCheckManager.java:208) at
org.eclipse.aether.internal.impl.DefaultArtifactResolver.gatherDownloads(DefaultArtifactResolver.java:563) at
org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads(DefaultArtifactResolver.java:481) at
org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:399) at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:
224) at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:338) at
org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:202) at
org.apache.maven.project.DefaultProjectBuilder.resolveDependencies(DefaultProjectBuilder.java:212) at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:185) at
org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:116) at org.eclipse.m2e.core.internal.embedder.MavenImpl.readMavenProject(MavenImpl.java:628) at
org.eclipse.m2e.core.internal.project.registry.DefaultMavenDependencyResolver.resolveProjectDependencies(DefaultMavenDependencyResolver.java:63) at
org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refreshPhase2(ProjectRegistryManager.java:525) at
org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.lambda$1(ProjectRegistryManager.java:489) at
org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:177) at
org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:151) at
org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:488) at
org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:349) at
org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:296) at
org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.configureNewMavenProjects(ProjectConfigurationManager.java:259) at
org.eclipse.m2e.core.internal.project.ProjectConfigurationManager$4.run(ProjectConfigurationManager.java:528) at
org.eclipse.m2e.core.internal.embedder.AbstractRunnable.call(AbstractRunnable.java:26) at org.eclipse.m2e.core.internal.embedder.AbstractRunnable.call(AbstractRunnable.java:1) at
org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:177) at
org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:151) at
org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:99) at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:1336) at
org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.enableMavenNature(ProjectConfigurationManager.java:525) at
org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.createSimpleProject(ProjectConfigurationManager.java:709) at
org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.createSimpleProject(ProjectConfigurationManager.java:662) at
com.amazonaws.eclipse.core.maven.MavenFactory.createMavenProject(MavenFactory.java:76) at
com.amazonaws.eclipse.sdk.ui.wizard.NewAwsJavaProjectWizard.doFinish(NewAwsJavaProjectWizard.java:215) at
com.amazonaws.eclipse.core.plugin.AbstractAwsProjectWizard$1$1.execute(AbstractAwsProjectWizard.java:63) at
org.eclipse.ui.actions.WorkspaceModifyOperation.lambda$0(WorkspaceModifyOperation.java:110) at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2295) at
org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2322) at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:131) at
com.amazonaws.eclipse.core.plugin.AbstractAwsProjectWizard$1.run(AbstractAwsProjectWizard.java:70) at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:
122)
Please check you settings.xml in Maven... this is to check if Maven would look for private repository or public one & make sure if it's a private repo like Nexus, you're connected to VPN..
then right click on the project & then Maven, the check force update of snapshots/ release & click OK..
I have a Google App Engine Standard Maven project, which I created with the appengine-standard-archetype archetype.
I want to use the ${project.version} variable as deploy version, but the value is not allowed for certain characters:
May only contain lowercase letters, digits, and hyphens. Must begin
and end with a letter or digit. Must not exceed 63 characters.
The value 0.0.1-SNAPSHOT need to be modified. I then used the build-helper-maven-plugin to obtain the replacement
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>version-urlsafe</id>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<name>project.version.urlsafe</name>
<value>${project.version}</value>
<regex>\.</regex>
<replacement>-</replacement>
<toLowerCase>true</toLowerCase>
<failIfNoMatch>false</failIfNoMatch>
</configuration>
</execution>
</executions>
</plugin>
And the maven-antrun-plugin to show the value
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>regex-replace-echo</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>******** Displaying value of property ********</echo>
<echo>${project.version.urlsafe}</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
At the end I used the new property as version for deploy
<app.deploy.version>${project.version.urlsafe}-urlsafe</app.deploy.version>
Note that I add the -urlsafe at the end of the value only to understand why the value is not considered
Running the deploy with mvn appengine:deploy I'm getting this output
...
[INFO] Executing tasks
main:
[echo] ******** Displaying value of property ********
[echo] 0-0-1-snapshot
...
gcloud.cmd app deploy --version ${project.version.urlsafe}-urlsafe
[INFO] GCLOUD: ERROR: (gcloud.app.deploy) argument --version/-v: Bad value [${project.version.urlsafe}-urlsafe]
Even if the ant-run plugin properly echoed the new version, when the deploy command is built, the variable itself is missing.
I then tried forcing the regex-property goal before the deploy, like follows
mvn build-helper:regex-property appengine:deploy
but I'm getting a missing configuration error in this case:
[ERROR] Failed to execute goal org.codehaus.mojo:build-helper-maven-plugin:3.0.0:regex-property (default-cli) on project maventest: The parameters 'regex', 'name', 'value' for goal org.codehaus.mojo:build-helper-maven-plugin:3.0.0:regex-property are missing or invalid -> [Help 1]
A little digression:
I decided to manually run the build-helper:regex-property as additional goal due to a previous experience with a similar a case: a plugin that inject a new variable, which is properly echoed but when it comes to use the value, is missing. Here is the reference: Unable to obtaing git.branch property
Cooperating with the plugin author we found that adding the plugin goal before the appengine one can solve the issue mvn git-commit-id:revision appengine:deploy. At the end the root cause of this problem was a Maven bug: https://issues.apache.org/jira/browse/MNG-6260
So even the workaround of directly calling the plugin is not suitable in this case due to a plugin configuration error.
How can issue can be solved? How can I obtain the ${project.version.urlsafe} variable properly created when executing the appengine deploy?
I had the same problem using the appengine-maven-plugin. And you're right, you need to first call the goal build-helper:regex-property before deploying on app engine.
But to make this work, you have to move the configuration part outside the executions tag.
Here is the complete configuration I am currently using:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<name>project.version.urlsafe</name>
<value>${project.version}</value>
<regex>\.</regex>
<replacement>-</replacement>
<toLowerCase>true</toLowerCase>
<failIfNoMatch>false</failIfNoMatch>
<fileSet/>
<source/>
</configuration>
</plugin>
Then when calling mvn build-helper:regex-property appengine:deploy, everything should work as expected.
I use Maven to manage my Java projects build but sometimes I have projects written in C or C++ langage and I would like to use Maven too so it will be easier to manage those projects.
It seems the nar-maven-plugin should do the job. I tried to create an HelloWorld project just to test it. I thought it will be really simple as it is generally with Maven.
My pom.xml
<project
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.sample</groupId>
<artifactId>helloworld-cplusplus-sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>nar</packaging>
<name>Helloworld</name>
<build>
<plugins>
<plugin>
<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<libraries>
<library>
<type>executable</type>
</library>
</libraries>
</configuration>
</plugin>
</plugins>
</build>
</project>
And i have the following error
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Unknown packaging: nar # line 7, column 14
#
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project com.sample:helloworld-cplusplus-sample:0.0.1-SNAPSHOT (D:\local\workspaces\TEST\HelloWorl
dMaven\pom.xml) has 1 error
[ERROR] Unknown packaging: nar # line 7, column 14
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
I'm using Maven 3.3.1.
I forced the download of nar-maven-plugin in my local repository using "mvn dependency:get ..." but it doesn't change anything.
When a plugin adds a new packaging type, you must add <extensions>true</extensions> to its definition:
<plugin>
<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<version>3.2.3</version>
<extensions>true</extensions> <!-- This needs to be present for a new packaging -->
<configuration>
<libraries>
<library>
<type>executable</type>
</library>
</libraries>
</configuration>
</plugin>
As already answered, ;)
link.exe is part of Microsoft Visual Studio, which is what NAR
typically uses under the hood to compile C++ code on Windows.
Try with
<linker>
<name>g++</name>
</linker>
in your nar plugin configuration if you have MinGW or something other than MSVS.
I am trying to build a simple C++ project with maven and the nar-maven-plugin, but I'm getting the following error:
Failed to execute goal
com.github.maven-nar:nar-maven-plugin:3.2.3:nar-validate
(default-nar-validate) on project it0015-cpp-executable: Could not
launch cmd.exe /X /C "link /?": Error while executing process. Cannot
run program "link": CreateProcess error=2, The system cannot find the
file specified -> [Help 1]
I am using Windows 8.1. Does anyone have ideas on how to investigate this issue?
you should specify the linker you are using.
For me, i'm using MinGW so i update my user path (environment variable) with C:/MinGW/bin and in the nar-maven-plugin i specify the linker name to g++
<plugin>
<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<version>3.2.3</version>
<extensions>true</extensions>
<configuration>
<linker>
<name>g++</name>
</linker>
<libraries>
<library>
<type>executable</type>
</library>
</libraries>
</configuration>
</plugin>
Now you can launch "mvn validate" to check if it works
When I using the follow structure on our Maven project:
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<args>
<arg>-g:line</arg>
</args>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.5.8.201207111220</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
The tests are executed but the jacoco.exec file is not created. I tried to add this tag destFile to prepare-agent goal but have not success (the file with coverage information is not created).
Anyone have any form to calculate code coverage of unit test for Scala using maven and Jacoco?
Work of Jacoco maven plugin depends on versions of JDK, Scala and plugin itself.
Just added the same config and it works properly: both jacoco.exec and site/jacoco with reports are in the target dir: https://github.com/plokhotnyuk/calculator/commit/e3a84db02dd942b0df71d4fa337df29512e213f6
Then got agent failure when using latest (0.6.2.201302030002) version of Jacoco maven plugin:
Caused by: java.lang.RuntimeException: Class java/util/UUID could not be instrumented.
at org.jacoco.agent.rt.internal_5d10cad.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
at org.jacoco.agent.rt.internal_5d10cad.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:99)
at org.jacoco.agent.rt.internal_5d10cad.PreMain.createRuntime(PreMain.java:51)
at org.jacoco.agent.rt.internal_5d10cad.PreMain.premain(PreMain.java:43)
... 6 more
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
at java.lang.Class.getField(Class.java:1542)
at org.jacoco.agent.rt.internal_5d10cad.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:136)
... 9 more
FATAL ERROR in native method: processing of -javaagent failed
Exception in thread "main"
And then the failure was worked out by switching from JDK8 to JDK7. Coverage report digits didn't changed.
Also after switching to Scala 2.10 source line highlighting started looks different:
Scala 2.9
Scala 2.10