I'm a .NET developer who needs to use the Java platform for a new project.
"Solutions" are a useful Visual Studio concept. How do I break my Java solution into "projects" (I guess Java packages) which have build interdependencies in the same source control repository?
We're planning to use Maven for third-party dependencies, and Scala for writing some of the libraries.
We also need to be IDE-independent.
Recommendations gratefully received!
Edit: Let us assume the solution will contain a web application, a console application, and a library written in Scala.
I have set up a similar model that you can study.
By using Maven it will be as IDE-agnostic as it can. You will not have to store any specific IDE settings in your VCS, just the source code and the pom files. Each developer will launch his IDE and point to the top pom and the project should load. Local settings will be created but should be ignored when committing to the VCS.
First of all a multi module Maven project will most definitely have a very similar layout as a C# solution with its projects. The top-folder with the parent-pom will be like the solution with the shared configurations and build order etc. Then the sub-folders with the sub-poms will match the project definitions with dependencies between other projects.
directory layout
+- pom.xml
+- scala
| +- pom.xml
| +- src
| +- main
| +- scala
+- console
| +- pom.xml
| +- src
| +- main
| +- java
+- web
+- pom.xml
+- src
+- main
+- java
+- resources
+- webapp
+- WEB-INF
-- web.xml
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>com.stackoverflow</groupId>
<artifactId>Q11226363</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>${project.artifactId}-${project.version}</name>
<properties>
<scala.version>2.9.2</scala.version>
</properties>
<modules>
<module>scala</module>
<module>web</module>
<module>console</module>
</modules>
<dependencyManagement>
<dependencies>
<!-- Inter-Module dependencies -->
<dependency>
<groupId>com.stackoverflow</groupId>
<artifactId>Q11226363-scala</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>scala-tools.org</id>
<name>Scala Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</pluginRepository>
</pluginRepositories>
</project>
scala/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>
<parent>
<groupId>com.stackoverflow</groupId>
<artifactId>Q11226363</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>Q11226363-scala</artifactId>
<name>${project.artifactId}-${project.version}</name>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
<phase>compile</phase>
</execution>
<execution>
<id>test-compile</id>
<goals>
<goal>testCompile</goal>
</goals>
<phase>test-compile</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
console/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>
<parent>
<groupId>com.stackoverflow</groupId>
<artifactId>Q11226363</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>Q11226363-console</artifactId>
<name>${project.artifactId}-${project.version}</name>
<dependencies>
<dependency>
<groupId>com.stackoverflow</groupId>
<artifactId>Q11226363-scala</artifactId>
</dependency>
</dependencies>
</project>
web/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>
<parent>
<groupId>com.stackoverflow</groupId>
<artifactId>Q11226363</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>Q11226363-web</artifactId>
<packaging>war</packaging>
<name>${project.artifactId}-${project.version}</name>
<dependencies>
<dependency>
<groupId>com.stackoverflow</groupId>
<artifactId>Q11226363-scala</artifactId>
</dependency>
</dependencies>
<build>
<finalName>webapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</build>
</project>
scala/src/main/scala/com/stackoverflow/Q11226363/ScalaApp.scala
/**
* @author maba, 2012-06-28
*/
package com.stackoverflow.Q11226363
class ScalaApp {
def helloScala():String = "Hello from Scala!"
}
console/src/main/java/com/stackoverflow/Q11226363/JavaApp.java
package com.stackoverflow.Q11226363;
/**
* @author maba, 2012-06-28
*/
public class JavaApp {
public static void main(String[] args) {
ScalaApp scalaApp = new ScalaApp();
System.out.println("Scala says: " + scalaApp.helloScala());
}
}
That has been tested by me. There can of course be some improvements to the pom files and dependencies but it is a good start.
If you look in the web/target
you will find your webapp.war
which will include the dependencies needed.
It is of course possible to split all these modules up and build them separately and still have dependencies between them but as I said it is a good starting point.
My personal approach is to use Maven for both:
This works pretty well and I believe it is IDE independent (although I've only tested it on Eclipse)
Note:
If you have a team working together on the same artifacts you will need some way to have a shared repository containing them, although this can be done quite simply by e.g.:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With