I want to run some code after the eclipse goal of the eclipse plugin (eclipse:eclipse) runs.
The documentation of the eclipse plugin says that the generate-resources phase is execute prior to the eclipse goal, but it doesn't mention any phase that is executed after.
I wanted to include the code with the gmaven-plugin but I can't find the right configuration:
<execution>
<id>delete_generated_sources_from_cp</id>
<phase>generate-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<providerSelection>1.7</providerSelection>
<source>
modifyClasspath.groovy
</source>
</configuration>
</execution>
Simply add the plugin you want to execute to your project. If you add an execution of the plugin to the phase process-resourcesit will execute after the eclipse plugin if you run mvn process-resources (or any phase after process-resources)
You could also invoke them directly: mvn eclipse:eclipse otherplugin:goal
eclipse:eclipse is not good way for executing the codes. I mean if you want to import project to eclipse, you should use 'eclipse:eclipse' otherwise you shouldn't.
Executing the code is depend on you codes; if this is web based, you should deploy it in your application server. If it has executable main class, you should execute it with 'java' command.
I wanted to include the code with the gmaven-plugin but I can't find the right configuration
I could not understand what you mean. could you explain more ..
Related
This question already has answers here:
How do I run a selenium test using maven from the command line?
(4 answers)
Closed 7 years ago.
I'm trying to figure out how to run Selenium WebDriver tests without having to use Eclipse or IntelliJ or any other IDE. I do all my java development using a plain text editor, and don't want to have to install (and learn) an IDE just for the sake of compiling and running tests.
I've tried following the Selenium documentation, but it stops short of actually telling you how to run the tests from the command line.
My brief experience with maven amounts to the following:
$ mvn compile
<snip>
No sources to compile
$ mvn test
<snip>
No tests to run
$ mvn run
<snip>
Invalid task 'run'
The only other one I know is mvn jetty:run but that doesn't seem right as I'm not wanting to run a new web server.
I suspect I just need to set the correct targets etc in my pom.xml, but I don't know what they should be, and surprisingly can't find any online.
Can anyone help please?
In short:
mvn integration-test or mvn verify is the thing you're looking for.
Explanation
The goals, you're invoking, are lifecycle phases of maven (see Maven Lifecycle Reference). mvn test is intended for standalone unit tests, mvn integration-test runs after compiling, testing and packaging. That would be also the phase, where you invoke Selenium tests. If you need to start and stop Jetty, Tomcat, JBoss, etc., you would bind start/stop of these to pre-integration-test and post-integration-test.
I usually run my integration-tests using Failsafe and perform there invocations to Selenium and other integrative tests.
OK, I finally figured it out after realising that this is actually a Maven-specific question rather than Eclipse or Selenium.
Maven can be made to run the code it compiles by using the exec-maven-plugin and adding the following to the pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>Selenium2Example</mainClass>
<arguments>
<argument>arg0</argument>
<argument>arg1</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
As you can probably gather from the snippet, arguments can be passed in by listing them in the pom.xml. Also, be sure to use the proper package name in the mainClass element.
You can then run mvn compile followed by mvn test to compile and run your code.
Credit has to go to http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/ for listing several ways to do this.
i am new to maven and learning how and when phases/goals get executed in plugin
Say i have below code snippet in my pom
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>1.4</version>
</plugin>
Now if i execute mvn install, all phases(and all goals corresponding to each phase) of modello that comes prior to install will be executed. Right?
But if do below modification to introduce specific goal, only one goal i.e java goal will be executed
(as it under generate-sources phase which comes prior to install phase). Is that correct?
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
</plugin>
No, it doesn't work like that. First of all, please use mvn verify (instead of install), unless you really want your project to be copied to your local repository.
If you only specify a plugin, which is not part of the default lifecycle (e.g. maven-compiler-plugin is already specified for the default lifecycle, all jars need to compile, right?), nothing will happen. So you need to specify which goals need to be executed within an execution-block. In some cases the goal has a default phase to bind to, e.g. modello:java binds by default to the generate-sources-phase. In this case you don't have to specify a <phase> in the execution-block.
I would like to run the following basic procedure within my Maven 3.0.4 project. I have all the basics in place and haven't had any issues but am running into problems on step #3. For some reason the basic solution is eluding me, since it seems like something that should be very obvious.
Run a basic clean/install (without annotation processing)
Request that a site build be run
Before the site build kicks off, run annotation processing on the compiled classes using an annotation processor class that was compiled in the initial steps
I tried setting up the annotation processing goal as follows:
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>pre-site</phase>
<configuration>
<outputDirectory>${basedir}/target/generated-documentation</outputDirectory>
<processors>
<processor>com.mydomain.MyFancyAnnotationProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
</plugin>
For some reason this doesn't seem to be working.
I feel like I'm doing something very, very silly that is preventing it from working.
I am using the Maven Annotation Plugin instead of the basic, Mojo Apt Plugin. I don't mind switching if someone has a working solution with that one. I tried both without any immediate signs of success. Again, it feels like it's just something obvious that I'm overlooking.
Error received:
[INFO] diagnostic error: Annotation processor 'com.mydomain.MyFancyAnnotationProcessor' not found
[ERROR] error on execute: error during compilation
My guess would be that the plugin is not including the current project itself in its classpath. The best solution would be to separate the annotation processor into its own (sub-)module if possible. If you can't do that, you may be able to just add this project itself as a dependency of the plugin (using a <dependencies> section under the plugin node).
As a diagnostic note, you can run maven with the '-X' argument to see detailed info about the build. This should show you exactly what is on the classpath when the plugin is executed.
Are there an option to skip tests with compilation errors? Just ignore them or treat them as failed?
The maven-compiler-plugin is responsible for compiling your tests during the test-compile phase. This plugin is configured to fail the build if any test classes fail to compile. You could experiment with the failOnError configuration. But I doubt you'll get the results you expect. The compilation process stops immediately when it encounters a compilation error. So potentially issue free classes may not have been re-compiled. Therefore there will be no guarantee the .class files you execute during the test phase will be 'up to date' with the corresponding .java source files.
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<failOnError>false</failOnError>
</configuration>
</execution>
</executions>
</plugin>
Not recommended...
mvn -DskipTests=true clean compile
Remember, with great power comes great responsibility.
use the following command to skip the entire test source folder. Through there are compilation errors in the test classes maven wont consider those, if you use the following command.
mvn clean install -Dmaven.test.skip=true
-DskipTests usually works. For instance, mvn install -DskipTests.
If you need to tell maven strictly to ignore - use -Dmaven.test.skip=true. This will force all the plugins and compiler to ignore the tests
Edited: Looks like -DskipTests=true also works!
Up until now we used Ant in my company. Whenever we wanted to send the application to the client we run a special Ant script that packaged all our source code with all jar libraries and Ant itself along with a simple batch file.
Then the client could put the files on a computer with no network access at all (and not even Ant) and run the batch file. As long as the computer had a valid JDK the batch script would compile all the code using the jars and create a WAR/EAR that would finally be deployed by the client on the application server.
Lately we migrated to Maven 2. But I haven't found a way to do the same thing. I have seen the Maven assembly plugin but this just creates source distributions or binary ones. Our scenario is actually a mix since it contains our source code but binary jars of the libraries we use (e.g. Spring, Hibernate)
So is it possible to create with Maven a self-contained assembly/release/package that one can run in a computer with no network access at all??? That means that all libraries should be contained inside.
Extra bonus if Maven itself is contained inside as well, but this is not a strict requirement. The final package should be easily compiled by just one command (easy for a system administrator to perform).
I was thinking of writing my own Maven plugin for this but I suspect that somebody has already encountered this.
From your dev environment, if you include the following under build plugins
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
and invoke mvn assembly:assembly, you would get yourApp-version-with-dependencies.jar in the target folder. This is a self-sufficient jar, and with a Main-class MANIFEST.MF entry, anybody can double click and run the application.
You might try this approach:
Use mvn ant:ant to create ant build
scripts from a maven project
Make sure ant is a project dependency
Use the assembly to build an ant
system
or plan b:
Use mvn ant:ant to create ant build
scripts from a maven project
Make sure ant is a project dependency
Write a "bootstrap class" to call Ant and run the build
Use appassembler to build a
scripted build and install environment
In plan b, you'd write scripts to set up a source tree someplace from the packaged source jars, and then use the appassembler build bat or sh scripts to call the bootstrap and build via ant. Your bootstrap can do anything you need to do before or after the build.
Hope this helps.
Perhaps an answer that I submitted for a similar question could be of some assistance. See Can maven collect all the dependant jars for a project to help with application deployment? The one piece missing is how to include the source code in the assembly. I have to imagine that there is some way to manage that with the assembly plugin. This also doesn't address the inclusion of Maven in the distribution.
What was the reason for moving from Ant to Maven? It sounds like you had everything worked out well with the Ant solution, so what is Maven buying you here?
If it is just dependency management, there are techniques for leveraging Maven from Ant that give you the best of both worlds.
the source plugin will give you a jar containing the source of a probject "source:jar". you could then use the assembly plugin to combine the source jars from your internal projects (using the sources to reference these source jars) and the binary jars from the external projects into one distribution.
however, as for turning this into a compilable unit, i have no suggestions. you could certainly bundle maven, but you'd need to create a bundle containing all the plugins you need to build your project! i don't know of any existing tool to do that.
This is how I do it... on the build part of the pom add in this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
And then on the profiles section add this bit in:
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
And when I do a maven install it builds the jar and also checks in a jar of the source.