You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by deckrider+mvn <de...@gmail.com> on 2007/12/14 19:27:25 UTC

two compiles from the same source

I have a requirement to build two different jars (one for java 1.4 and
one for java 1.5) from the same source.  Is this the best way to make
such a project or are there better aproaches?

Layout:

foo-parent/pom.xml
foo-parent/foo14
foo-parent/foo14/pom.xml
foo-parent/foo15
foo-parent/foo15/pom.xml
foo-parent/src
foo-parent/src/main
foo-parent/src/main/java
foo-parent/src/main/java/com
foo-parent/src/main/java/com/example
foo-parent/src/main/java/com/example/Test.java

foo-parent/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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <packaging>pom</packaging>
  <artifactId>foo-parent</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <name>Foo Parent</name>
  <url>http://impact.vzbi.com</url>
  <modules>
    <module>foo15</module>
    <module>foo14</module>
  </modules>
</project>

foo-parent/foo14/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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
     <groupId>com.example</groupId>
     <artifactId>foo-parent</artifactId>
     <version>1.0.0-SNAPSHOT</version>
  </parent>
  <groupId>com.example</groupId>
  <name>Foo 1.4</name>
  <artifactId>foo14</artifactId>
  <packaging>jar</packaging>
  <build>
    <sourceDirectory>../src</sourceDirectory>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.4</source>
          <target>1.4</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

foo-parent/foo15/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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
     <groupId>com.example</groupId>
     <artifactId>foo-parent</artifactId>
     <version>1.0.0-SNAPSHOT</version>
  </parent>
  <groupId>com.example</groupId>
  <name>Foo 1.5</name>
  <artifactId>foo15</artifactId>
  <packaging>jar</packaging>
  <build>
    <sourceDirectory>../src</sourceDirectory>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: two compiles from the same source

Posted by Stuart McCulloch <st...@jayway.net>.
On 15/12/2007, deckrider+mvn <de...@gmail.com> wrote:
>
> I have a requirement to build two different jars (one for java 1.4 and
> one for java 1.5) from the same source.  Is this the best way to make
> such a project or are there better aproaches?


you could build for 1.5 and then retrotranslate it for 1.4 in the same
build:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>retrotranslator-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>translate-project</goal>
            </goals>
            <configuration>
                <classifier>jdk14</classifier>
                <attach>true</attach>
            </configuration>
        </execution>
    </executions>
</plugin>

http://mojo.codehaus.org/retrotranslator-maven-plugin/examples/project-translation.html

Layout:
>
> foo-parent/pom.xml
> foo-parent/foo14
> foo-parent/foo14/pom.xml
> foo-parent/foo15
> foo-parent/foo15/pom.xml
> foo-parent/src
> foo-parent/src/main
> foo-parent/src/main/java
> foo-parent/src/main/java/com
> foo-parent/src/main/java/com/example
> foo-parent/src/main/java/com/example/Test.java
>
> foo-parent/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/maven-v4_0_0.xsd">
>   <modelVersion>4.0.0</modelVersion>
>   <groupId>com.example</groupId>
>   <packaging>pom</packaging>
>   <artifactId>foo-parent</artifactId>
>   <version>1.0.0-SNAPSHOT</version>
>   <name>Foo Parent</name>
>   <url>http://impact.vzbi.com</url>
>   <modules>
>     <module>foo15</module>
>     <module>foo14</module>
>   </modules>
> </project>
>
> foo-parent/foo14/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/maven-v4_0_0.xsd">
>   <modelVersion>4.0.0</modelVersion>
>   <parent>
>      <groupId>com.example</groupId>
>      <artifactId>foo-parent</artifactId>
>      <version>1.0.0-SNAPSHOT</version>
>   </parent>
>   <groupId>com.example</groupId>
>   <name>Foo 1.4</name>
>   <artifactId>foo14</artifactId>
>   <packaging>jar</packaging>
>   <build>
>     <sourceDirectory>../src</sourceDirectory>
>     <plugins>
>       <plugin>
>         <groupId>org.apache.maven.plugins</groupId>
>         <artifactId>maven-compiler-plugin</artifactId>
>         <configuration>
>           <source>1.4</source>
>           <target>1.4</target>
>         </configuration>
>       </plugin>
>     </plugins>
>   </build>
> </project>
>
> foo-parent/foo15/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/maven-v4_0_0.xsd">
>   <modelVersion>4.0.0</modelVersion>
>   <parent>
>      <groupId>com.example</groupId>
>      <artifactId>foo-parent</artifactId>
>      <version>1.0.0-SNAPSHOT</version>
>   </parent>
>   <groupId>com.example</groupId>
>   <name>Foo 1.5</name>
>   <artifactId>foo15</artifactId>
>   <packaging>jar</packaging>
>   <build>
>     <sourceDirectory>../src</sourceDirectory>
>     <plugins>
>       <plugin>
>         <groupId>org.apache.maven.plugins</groupId>
>         <artifactId>maven-compiler-plugin</artifactId>
>         <configuration>
>           <source>1.5</source>
>           <target>1.5</target>
>         </configuration>
>       </plugin>
>     </plugins>
>   </build>
> </project>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Cheers, Stuart