13

Does anyone know any simple yet effective way to build all Maven projects in current workspace, for example, maven clean install for each such project.

Is it for example possible to select multiple projects and use something similar to ${project_loc} or get a popup with possible projects to use for the run configuration? Or any other way?

I'm using Eclipse Juno.

JLund
  • 496
  • 1
  • 4
  • 14

2 Answers2

15

Can you give them all a parent pom.xml and then mvn compile the parent pom.xml?

Look for project inheritance here.

If you can specify relative paths, this shouldn't be too hard. Create a new maven project with a pom.xml something like:

<?xml version="1.0"?>
<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>
    <groupId>com.example</groupId>
    <artifactId>parent-app</artifactId>
    <packaging>pom</packaging>
    <version>1</version>
    <modules>
        <module>../project1</module>
        <module>../project2</module>
    </modules>
</project>

Delete the projects from your Eclipse workspace (but not the file system) and then import the parent maven project. Now you can:

Run As... > Maven build > clean compile (as Goals)

and it should clean and compile all the projects.

davidfmatheson
  • 3,539
  • 19
  • 27
  • 1
    The projects are completely unrelated. Do you suggest that I create a new project with a pom that specifies which projects to include in the build? If so, do you have an example? The projects already inherit from a parent pom, which I "cannot" edit. – JLund Aug 03 '12 at 14:51
  • Answer edited to provide more info. I just saw the last part of your comment, though, about the parent pom. The subprojects (project1 and project2) do not have to identify that pom as their parent pom, but I'm still not sure if that will work for you. Try it out, though. – davidfmatheson Aug 03 '12 at 15:07
  • If I need different goals on different projects? – Ori Marko Aug 09 '18 at 10:44
  • worked well for me.. though I initiated mvn package from terminal (y) – Vikash Apr 08 '19 at 15:58
2

As a launch configuration is always related to one project, there is no way to put many projects into a launch configuration by pure Eclipse tooling. However, there are some workarounds:

  • Use a parent.pom to have a new project including all the existing ones (and doing the iteration in Maven).
  • Really define a launch config for each project and then use either CDTs launch groups or the EclipseRunner plugin to launch them batch like.
  • Use an Ant script to iterate over your workspace directories and call the launch config using Ant4Eclipse.

That said, your best bet is the parent.pom, as it is a proven way and you can reuse that on your continuous integration server.

Bananeweizen
  • 21,797
  • 8
  • 68
  • 88