Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
282 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...