multiple profiles & tokenized dependency

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

multiple profiles & tokenized dependency

Kyunam Kim
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
Reply | Threaded
Open this post in threaded view
|

Re: multiple profiles & tokenized dependency

Anders Hammar
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 <[hidden email]> 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
>