Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Out-of-tree build with maven. Is it possible?

Tags:

java

maven

build

I start learning packaging for several distros (currently Cygwin and Debian).

They have requirement to build system to allow out-of-tree build (synonym out-of-source build):

http://wiki.debian.org/UpstreamGuide#Out-of-Tree_Builds

To work-around "dumb" build system for example cygport recommend use lndir (from xutils project):

  lndir ${S} ${B}
  cd {B}
  ...build-commands...

I read mvn(1) man page but doesn't found anything appropriated. Next I just try:

  $ mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
  ...
  $ pwd
  /maven/simple
  $ ls 
  my-app
  $ mvn -f my-app/pom.xml compile
  ...
  [INFO] --- maven-compiler-plugin:2.0.2:compile (default-compile) @ my-app ---
  [INFO] Compiling 1 source file to /maven/simple/my-app/target/classes

As you can see target directory created in source root hierarchy while I look for a way to avoid this.

Is it possible out-of-tree build with maven? And how?

like image 747
gavenkoa Avatar asked Nov 01 '12 07:11

gavenkoa


People also ask

Can Maven be used for non Java projects?

Can Maven Be Used For Non-Java Projects? Yes. There are hundreds of archetypes for Maven, ranging from Java web application development to eBook publishing.

Is Maven only for Java projects?

Maven is chiefly used for Java-based projects, helping to download dependencies, which refers to the libraries or JAR files. The tool helps get the right JAR files for each project as there may be different versions of separate packages.

Is Maven a build technology?

Maven is a build automation tool used primarily for Java projects. Maven can also be used to build and manage projects written in C#, Ruby, Scala, and other languages. The Maven project is hosted by the Apache Software Foundation, where it was formerly part of the Jakarta Project.

What can be done with Maven?

Maven is such a build management tool which can do all the things like adding dependencies, managing the classpath to project, generating war and jar file automatically and many other things.


2 Answers

You could do like this to get it in your current working directory:

<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>Q13173063</artifactId>
    <version>1.0-SNAPSHOT</version>

    <name>${project.artifactId}-${project.version}</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <buildDir>${user.dir}</buildDir>
    </properties>

    <build>
        <directory>${buildDir}</directory>
    </build>
</project>

Then you can issue

mvn -f my-app/pom.xml compile

And it will give you your classes in the current working directory.

And easily change to another output directory:

mvn -f my-app/pom.xml -DbuildDir=/tmp/build compile
like image 130
maba Avatar answered Sep 28 '22 04:09

maba


It might be as simple as having a

<build>
    <directory>/your/build/directory</directory>
</build>

in your pom.xml. /your/build/directory need not be in the source tree and can be parameterized using the usual ${...} syntax.

Cheers,

like image 36
Anders R. Bystrup Avatar answered Sep 28 '22 06:09

Anders R. Bystrup