run jasmine.js test as part of Maven 'test' goal - maven

I have the following jasmine tests configuration in my project pom.xml:
<pluginManagement>
<plugins>
<plugin>
<groupId>com.github.searls</groupId>
<artifactId>jasmine-maven-plugin</artifactId>
<version>1.1.0</version>
<executions>
<execution>
<goals>
<goal>test</goal>
<goal>jasmine</goal>
</goals>
</execution>
</executions>
<configuration>
<jsSrcDir>${basedir}/src/main/js</jsSrcDir>
<sourceIncludes>
<include>myCode.js</include>
</sourceIncludes>
<jsTestSrcDir>${basedir}src/test/js/specs</jsTestSrcDir>
<specIncludes>
<include>mySpec.js</include>
</specIncludes>
</configuration>
</plugin>
...
with this configuraton I can run jsamine:test and the test wil run.
I want to run the tests as part of the goal test, but Maven won't run them.
I even tried removing the line <goal>jasmine</goal> but Maven still won't run the jasmine tests.
What am I doing wrong?

You must also add the execution of the plugin like this into you project:
<project>
<build>
<plugins>
<plugin>
<groupId>com.github.searls</groupId>
<artifactId>jasmine-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
cause the one you've defined in pluginManagement does not really execute the plugin.

Related

What does exactly mean to have the two goal sections (integration-test and verify) inside de failsafe plugin in maven?

<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.21.0</version>
<executions>
<execution>
<goals>
**<goal>integration-test</goal>
<goal>verify</goal>**
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
I'm new with Maven and I don't understand what means to have both goals declared inside the plugin in the pom.xml. Thank you.
From plugin Documentation
Goals Overview
The Failsafe Plugin has only two goals:
failsafe:integration-test runs the integration tests of an application.
failsafe:verify verifies that the integration tests of an application passed.

Run Maven goal only in parent POM by activation

I am working on integrating a plugin into a multi-module project.
I am using a 3rd party plugin that essentially needs to only by run from the parent project (based on my understanding and usage of it). I tried to accomplish this by using a profile, like so:
<profiles>
<profile>
<id>run-my-guy</id>
<build>
<plugins>
<plugin>
<groupId>com.myproject</groupId>
<artifactId>myproject-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>runThing</goal>
</goals>
<inherited>false</inherited>
</execution>
</executions>
<inherited>false</inherited>
</plugin>
</plugins>
</build>
</profile>
</profiles>
I have several <inherited>false</inherited>, but if I run mvn help:all-profiles I can still see this profile in every single module. If I run my mvn package -P run-my-guy I see this get executed in every single subproject. I want the ability to activate this and I do not want it to be on by default.
If I try to add it the <build> section, like this:
<build>
<plugins>
<plugin>
<groupId>com.myproject</groupId>
<artifactId>myproject-maven-plugin</artifactId>
<inherited>false</inherited>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>runThing</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Here, I also have a few <inherited>false</inherited>, just to try and enforce that the plugin and the execution are not inherited. However, whenI run the package phase, or anything that includes that phase, the runThing goal is included.
How do I run a goal only by activation (like profile or some other feature, or just by explicitly running the goal) and only in the parent?
As shown in an answer for "Run a single Maven plugin execution?", it is now possible (since Maven 3.3.1) to specify an execution Id for a direct goal invocation.
pom.xml
<build>
<plugins>
<plugin>
<groupId>com.myproject</groupId>
<artifactId>myproject-maven-plugin</artifactId>
<inherited>false</inherited>
<executions>
<id>myproject-exec-id</id> <!-- note the execution Id -->
<execution>
<phase>none</phase>
<goals>
<goal>runThing</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
And then invoking the goal from the command line uses the optional #executionId parameter:
mvn myproject:runThing#myproject-exec-id

Is isolation of failsafe and surefire runs from each other using a skip approach possible?

The value of property skipITs when overridden on the command line appears to be ignored by maven if used in conjunction with -Dit.test=full.Classname. The specified failsafe test will not be run (case one).
As opposed to this specifiing skipITs without the it.test switch leads to running of existing failsafe tests (case two).
Background: Am trying to isolate surefire tests from failsafe tests runs by namely either running both types of them or one of each only. The maven calls are:
mvn -Pintegration -DskipTests=true -DskipITs=false -Dit.test=full.Classname verify
in the first case and:
mvn -Pintegration -DskipTests=true -DskipITs=false verify
in the second.
The relevant configuration (pom.xml, snippets only) being:
<properties>
<skipTests>false</skipTests>
<skipITs>false</skipITs>
</properties>
(those are defaults) and
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<id>custom<id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<skipTests>${skipITs}</skipTests>
<skip>${skipITs}</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Did you observe that too or have you eventually found a better working approach?
By default, the Surefire plugins runs during the test phase and usually you configure the Failsafe plugin to run during the integration-test and verify phase like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
To run the Surefire tests only, use
mvn clean test
To run both the Surefire and the Failsafe tests, use
mvn clean verify
You can completely skip any plugin by using the <skip> configuration option. If you configure the Surefire plugin like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<skip>${skip.surefire}</skip>
</configuration>
</plugin>
you can run only the Failsafe tests by calling
mvn clean verify -Dskip.surefire=true
If the integration test (it.test) has a non-default name I need to add an include pattern accordingly, like in (pom.xml snippet):
<profiles>
<profile>
<id>dbUnit</id>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<id>custom</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<skipTests>${skipITs}</skipTests>
<skip>${skipITs}</skip>
<includes>
<include>**/*DbTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
But that appears valid only for the original approach. Also observe that the default inclusion patterns might need to be added too in case for your integration tests you followed different naming schemes.

Is it possible to get the list of active profiles in Maven?

In Maven, is there a way to get a list of the active profiles, say, as a property or as a text file?
More specifically, when I run:
mvn resources:resources -P MyProfile
I want to get the string MyProfile somewhere I can read it into my Java program.
Maven 3.2.1
Thanks
Edit
I attempted to configure the Maven Help plugin to run the active-profiles goal whenever the goal resources:resources is run by configuring an execution to participate in the process-resources phase as shown below. That did not work either ...:
<packaging>jar</packaging>
<build>
<plugins>
<!-- ... -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<version>2.2</version>
<configuration>
<output>${basedir}/target/active-profiles.txt</output>
</configuration>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>active-profiles</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
You could try this maven plugin. The configuration below will create a text file that will contain the profiles that were active during the build.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<version>2.2</version>
<configuration>
<output>${basedir}/target/active-profiles.txt</output>
</configuration>
</plugin>

Mvn compile before exec

I am trying to set up my POM such that when I do mvn exec:exec or mvn exec:java it will first compile the source and iff successful, execute it.
I have the following and have tried moving the <execution> part about but can't get it to work:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
<executions>
<execution>
<phase>exec</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>my.main.class</mainClass>
</configuration>
</plugin>
</plugins>
</build>
When I do either mvn exec:exec ... or mvn exec:java it doesn't first compile. I have tried putting the <execution> part in the exec plugin section but that didn't work either?
It's an old topic, but someone else might be interested in an alternative solution for this.
It's not exactly what you were looking for, but you can compile and execute using a single command:
mvn compile exec:exec
This way Maven will always compile the project before executing it.
You can bind the exec plugin to a phase following compile in build lifecycle (verify in the example below):
<profile>
<id>proxy</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<mainClass>my.main.class</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
and than run mvn verify.
I see the answer is very late and you may have found a solution.
I'm just leaving as a reference for others who may need it.
This will not quite answer the question but it will help us to accomplish the main objective you have.
Instead of executing a build goal when running the mvn exec:java we can execute the mvn exec:java when calling a 'post-build" phase/goal.
This will effectively make that phase unusable as it was because we will be substituting it by the execution but if we have a "post-build" goal that we are not using (like package or install) we can use it for the execution like so:
using package goal will end up like:
...
<properties>
...
<main.class>${project.groupId}.MainClass</main.class>
...
</properties>
...
<build>
<plugins>
...
<!-- region Forces the app to be executed when using mvn package -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<mainClass>${main.class}</mainClass>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- endregion -->
...
</plugins>
</build>
This way when we execute goal package with: mvn package the plugin will be executed and the application runned.

Resources