You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Kyunam Kim <ky...@hotmail.com> on 2018/01/03 04:10:53 UTC

multiple profiles & tokenized dependency

With the below pom.xml,

a) if I do "mvn clean package -P 1x,2x", will maven do "clean-compile-test-package" twice back to back using different dependency each time and produce two different jar files?
b) is it better to have explicit <dependencies/> & <build/> in each profile than tokenized  <dependencies/> & <build/> outside <profles/>?


<?xml version="1.0" encoding="UTF-8"?>
<project>

  <groupId>com.mycompany</groupId>
  <artifactId>mything</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <dependencies>
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-core_${scala.compact}</artifactId>
      <version>2.2.1</version>
    </dependency>
  </dependencies>

  <build>
    <finalName>${project.artifactId}-${project.version}-${scala.compact}</finalName>
    <plugins>
      <plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>scala-maven-plugin</artifactId>
        <version>3.3.1</version>
        <executions>
          ...
        </executions>
        <configuration>
          <scalaCompatVersion>${scala.compact}</scalaCompatVersion>
          <scalaVersion>${scala.version}</scalaVersion>
          <recompileMode>incremental</recompileMode>
          <useZincServer>false</useZincServer>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>1x</id>
      <properties>
        <scala.compact>2.10</scala.compact>
        <scala.version>${scala.compact}.6</scala.version>
      </properties>
    </profile>
    <profile>
      <id>2x</id>
      <properties>
        <scala.compact>2.11</scala.compact>
        <scala.version>${scala.compact}.8</scala.version>
      </properties>
    </profile>
  </profiles>

</project>

Thanks,
Kyunam

Re: multiple profiles & tokenized dependency

Posted by Anders Hammar <an...@hammar.net>.
a) No, it will only be one build lifecycle executed where both profiles are
applied. I suspect that the properties from the last profile specified have
precedence.
b) Using dependencies in profiles is not good practice. The reason is that
you're only looking at the build time but poms are also deployed to the
maven repo where they are used e.g. when others declare a dependency to the
artifact.

If your want to different artifacts during a build you should have a
multi-module build with two modules (projects) producing one artifact each.

On Wed, Jan 3, 2018 at 5:10 AM, Kyunam Kim <ky...@hotmail.com> wrote:

> With the below pom.xml,
>
> a) if I do "mvn clean package -P 1x,2x", will maven do
> "clean-compile-test-package" twice back to back using different dependency
> each time and produce two different jar files?
> b) is it better to have explicit <dependencies/> & <build/> in each
> profile than tokenized  <dependencies/> & <build/> outside <profles/>?
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <project>
>
>   <groupId>com.mycompany</groupId>
>   <artifactId>mything</artifactId>
>   <version>0.0.1-SNAPSHOT</version>
>   <packaging>jar</packaging>
>
>   <dependencies>
>     <dependency>
>       <groupId>org.apache.spark</groupId>
>       <artifactId>spark-core_${scala.compact}</artifactId>
>       <version>2.2.1</version>
>     </dependency>
>   </dependencies>
>
>   <build>
>     <finalName>${project.artifactId}-${project.version}
> -${scala.compact}</finalName>
>     <plugins>
>       <plugin>
>         <groupId>net.alchim31.maven</groupId>
>         <artifactId>scala-maven-plugin</artifactId>
>         <version>3.3.1</version>
>         <executions>
>           ...
>         </executions>
>         <configuration>
>           <scalaCompatVersion>${scala.compact}</scalaCompatVersion>
>           <scalaVersion>${scala.version}</scalaVersion>
>           <recompileMode>incremental</recompileMode>
>           <useZincServer>false</useZincServer>
>         </configuration>
>       </plugin>
>     </plugins>
>   </build>
>
>   <profiles>
>     <profile>
>       <id>1x</id>
>       <properties>
>         <scala.compact>2.10</scala.compact>
>         <scala.version>${scala.compact}.6</scala.version>
>       </properties>
>     </profile>
>     <profile>
>       <id>2x</id>
>       <properties>
>         <scala.compact>2.11</scala.compact>
>         <scala.version>${scala.compact}.8</scala.version>
>       </properties>
>     </profile>
>   </profiles>
>
> </project>
>
> Thanks,
> Kyunam
>