This page is no longer maintained — Please continue to the home page at www.scala-lang.org

A Maven project for both Scala 2.7.5 and 2.8.0-SNAPSHOT?

7 replies
Alexy Khrabrov
Joined: 2009-05-25,
User offline. Last seen 42 years 45 weeks ago.

I want to maintain two versions of my project, for Scala 2.7.5 and
Scala 2.8.0-SNAPSHOT.

One way to do it in Maven is with profiles, but I didn't explore it
yet. I compiled all dependencies with different versions: e.g.,
scala-json exists in Maven repository with versions
1.0-Scala-2.8.0-SNAPSHOT and 1.0-Scala-2.7.5. The Scala version
itself is defined by a property scala.version in the pom.xml.

I can see using inherited pom and setting the version separately; I
can have the main pom in a top directory and two versions of the
project in subdirectories... May also use git branches. Did anybody
set up something like that and what would you guys recommend?

Cheers,
Alexy

ebowman
Joined: 2009-04-13,
User offline. Last seen 1 year 30 weeks ago.
Re: A Maven project for both Scala 2.7.5 and 2.8.0-SNAPSHOT?

Alexy Khrabrov wrote:
> I want to maintain two versions of my project, for Scala 2.7.5 and
> Scala 2.8.0-SNAPSHOT.
>
> One way to do it in Maven is with profiles, but I didn't explore it
> yet. I compiled all dependencies with different versions: e.g.,
> scala-json exists in Maven repository with versions
> 1.0-Scala-2.8.0-SNAPSHOT and 1.0-Scala-2.7.5. The Scala version
> itself is defined by a property scala.version in the pom.xml.
>
> I can see using inherited pom and setting the version separately; I
> can have the main pom in a top directory and two versions of the
> project in subdirectories... May also use git branches. Did anybody
> set up something like that and what would you guys recommend?
>
> Cheers,
> Alexy
>
>

Maven profiles would be a reasonable way to do this.

Untested, but something like this should work in your pom:

scala-2.8-config

2.8.0-SNAPSHOT

scala-2.7.5-config

2.7.5

scala-2.8-config

So it defaults to 2.8; if you want to use 2.7, you would run maven like:

mvn -P scala-2.7.5-config

See
http://maven.apache.org/guides/introduction/introduction-to-profiles.html

cheers,
Eric

Joshua.Suereth
Joined: 2008-09-02,
User offline. Last seen 32 weeks 5 days ago.
Re: A Maven project for both Scala 2.7.5 and 2.8.0-SNAPSHOT?
At this point, I'd recommend separate branches.  2.8.0 has a lot of new features that are source-incompatable with older scala versions. 


Also, there has been work in the SBT community to unify how we cross-deploy a library for scala versions.  The current convention is as follows:

group/organization: <your group>
artifactId:   <your-artifact name>-${scala.version}
version: <your-library-verison>

This scheme works with SNAPSHOTs correctly (i.e. library 1.0-SNAPSHOT using Scala 2.8.0-SNAPSHOT is correctly identified.  Alexy's scheme (also initially used by myself) could cause issues with knowing who was the snapshot).

SBT has support baked in for multiple scala versions, and with maven it requires different poms (perhaps branches).


Hope this helps!!!
- Josh

On Tue, Jun 30, 2009 at 1:00 PM, Eric Bowman <ebowman [at] boboco [dot] ie> wrote:
Alexy Khrabrov wrote:
> I want to maintain two versions of my project, for Scala 2.7.5 and
> Scala 2.8.0-SNAPSHOT.
>
> One way to do it in Maven is with profiles, but I didn't explore it
> yet.  I compiled all dependencies with different versions: e.g.,
> scala-json exists in Maven repository with versions
> 1.0-Scala-2.8.0-SNAPSHOT and 1.0-Scala-2.7.5.  The Scala version
> itself is defined by a property scala.version in the pom.xml.
>
> I can see using inherited pom and setting the version separately; I
> can have the main pom in a top directory and two versions of the
> project in subdirectories...  May also use git branches.  Did anybody
> set up something like that and what would you guys recommend?
>
> Cheers,
> Alexy
>
>

Maven profiles would be a reasonable way to do this.

Untested, but something like this should work in your pom:

 <profiles>
   <profile>
     <id>scala-2.8-config</id>
     <properties>
       <scala.version>2.8.0-SNAPSHOT</scala.version>
     </properties>
   </profile>
   <profile>
     <id>scala-2.7.5-config</id>
     <properties>
       <scala.version>2.7.5</scala.version>
     </properties>
   </profile>

 </profiles>

 <activeProfiles>
   <activeProfile>scala-2.8-config</activeProfile>
 </activeProfiles>


So it defaults to 2.8; if you want to use 2.7, you would run maven like:

mvn -P scala-2.7.5-config

See
http://maven.apache.org/guides/introduction/introduction-to-profiles.html

cheers,
Eric

--
Eric Bowman
Boboco Ltd
ebowman [at] boboco [dot] ie
http://www.boboco.ie/ebowman/pubkey.pgp
+35318394189/+353872801532



Mark Harrah
Joined: 2008-12-18,
User offline. Last seen 35 weeks 3 days ago.
Re: A Maven project for both Scala 2.7.5 and 2.8.0-SNAPSHOT?

Just a minor correction to what Josh said- we use an underscore instead of a
dash:

artifactId: _${scala.version}

-Mark

On Tuesday 30 June 2009, Josh Suereth wrote:
> At this point, I'd recommend separate branches. 2.8.0 has a lot of new
> features that are source-incompatable with older scala versions.
>
>
> Also, there has been work in the SBT community to unify how we cross-deploy
> a library for scala versions. The current convention is as follows:
>
> group/organization:
> artifactId: -${scala.version}
> version:
>
> This scheme works with SNAPSHOTs correctly (i.e. library 1.0-SNAPSHOT using
> Scala 2.8.0-SNAPSHOT is correctly identified. Alexy's scheme (also
> initially used by myself) could cause issues with knowing who was the
> snapshot).
>
> SBT has support baked in for multiple scala versions, and with maven it
> requires different poms (perhaps branches).
>
>
> Hope this helps!!!
> - Josh
>
> On Tue, Jun 30, 2009 at 1:00 PM, Eric Bowman wrote:
> > Alexy Khrabrov wrote:
> > > I want to maintain two versions of my project, for Scala 2.7.5 and
> > > Scala 2.8.0-SNAPSHOT.
> > >
> > > One way to do it in Maven is with profiles, but I didn't explore it
> > > yet. I compiled all dependencies with different versions: e.g.,
> > > scala-json exists in Maven repository with versions
> > > 1.0-Scala-2.8.0-SNAPSHOT and 1.0-Scala-2.7.5. The Scala version
> > > itself is defined by a property scala.version in the pom.xml.
> > >
> > > I can see using inherited pom and setting the version separately; I
> > > can have the main pom in a top directory and two versions of the
> > > project in subdirectories... May also use git branches. Did anybody
> > > set up something like that and what would you guys recommend?
> > >
> > > Cheers,
> > > Alexy
> >
> > Maven profiles would be a reasonable way to do this.
> >
> > Untested, but something like this should work in your pom:
> >
> >
> >
> > scala-2.8-config
> >
> > 2.8.0-SNAPSHOT
> >
> >
> >
> > scala-2.7.5-config
> >
> > 2.7.5
> >
> >
> >
> >
> >
> >
> > scala-2.8-config
> >
> >
> >
> > So it defaults to 2.8; if you want to use 2.7, you would run maven like:
> >
> > mvn -P scala-2.7.5-config
> >
> > See
> > http://maven.apache.org/guides/introduction/introduction-to-profiles.html
> >
> > cheers,
> > Eric
> >
> > --
> > Eric Bowman
> > Boboco Ltd
> > ebowman [at] boboco [dot] ie
> > http://www.boboco.ie/ebowman/pubkey.pgp
> > +35318394189/+353872801532 >18394189/+353872801532>

Alexy Khrabrov
Joined: 2009-05-25,
User offline. Last seen 42 years 45 weeks ago.
Re: A Maven project for both Scala 2.7.5 and 2.8.0-SNAPSHOT?

A couple more important details: the minimalist pom.xml in 2.7/ or
2.8/ lists the orignal pom as parent, of course. Also for this scheme
to work I had to rename the original project's artifactId as
theproject-base, and then the scala-version-specific ones are called
theproject_${scala.version} (following Mark's correction), with
theproject-base in its lower pom pointing back to the
parent.

This way we have two completely compiled 2.{7.8}/target/
subdirectories at all times. (Still have to see how IDEA likes it.)

I also plan to play with the Maven profiles -- there, I'd like to keep
a separate target-${scala.version} build directory to have them all
around, doable?

Now the question moves to preprocessing scala-version specific
sources. Since there's no conditional compilation in scala itself
(really?), it's either CPP, or M4, or some Maven preprocessing voodoo.
Alternatively, it's got branches, but I have to figure out how to
tell git "these are the differences I authorize" and "merge everything
else" without manually supervising merges all the time.

Cheers,
Alexy

Jorge Ortiz
Joined: 2008-12-16,
User offline. Last seen 29 weeks 3 days ago.
Re: A Maven project for both Scala 2.7.5 and 2.8.0-SNAPSHOT?
I've been using Maven and Git, and keeping separate branches for each Scala version.

--j

On Tue, Jun 30, 2009 at 11:18 AM, Josh Suereth <joshua [dot] suereth [at] gmail [dot] com> wrote:
At this point, I'd recommend separate branches.  2.8.0 has a lot of new features that are source-incompatable with older scala versions. 


Also, there has been work in the SBT community to unify how we cross-deploy a library for scala versions.  The current convention is as follows:

group/organization: <your group>
artifactId:   <your-artifact name>-${scala.version}
version: <your-library-verison>

This scheme works with SNAPSHOTs correctly (i.e. library 1.0-SNAPSHOT using Scala 2.8.0-SNAPSHOT is correctly identified.  Alexy's scheme (also initially used by myself) could cause issues with knowing who was the snapshot).

SBT has support baked in for multiple scala versions, and with maven it requires different poms (perhaps branches).


Hope this helps!!!
- Josh

On Tue, Jun 30, 2009 at 1:00 PM, Eric Bowman <ebowman [at] boboco [dot] ie> wrote:
Alexy Khrabrov wrote:
> I want to maintain two versions of my project, for Scala 2.7.5 and
> Scala 2.8.0-SNAPSHOT.
>
> One way to do it in Maven is with profiles, but I didn't explore it
> yet.  I compiled all dependencies with different versions: e.g.,
> scala-json exists in Maven repository with versions
> 1.0-Scala-2.8.0-SNAPSHOT and 1.0-Scala-2.7.5.  The Scala version
> itself is defined by a property scala.version in the pom.xml.
>
> I can see using inherited pom and setting the version separately; I
> can have the main pom in a top directory and two versions of the
> project in subdirectories...  May also use git branches.  Did anybody
> set up something like that and what would you guys recommend?
>
> Cheers,
> Alexy
>
>

Maven profiles would be a reasonable way to do this.

Untested, but something like this should work in your pom:

 <profiles>
   <profile>
     <id>scala-2.8-config</id>
     <properties>
       <scala.version>2.8.0-SNAPSHOT</scala.version>
     </properties>
   </profile>
   <profile>
     <id>scala-2.7.5-config</id>
     <properties>
       <scala.version>2.7.5</scala.version>
     </properties>
   </profile>

 </profiles>

 <activeProfiles>
   <activeProfile>scala-2.8-config</activeProfile>
 </activeProfiles>


So it defaults to 2.8; if you want to use 2.7, you would run maven like:

mvn -P scala-2.7.5-config

See
http://maven.apache.org/guides/introduction/introduction-to-profiles.html

cheers,
Eric

--
Eric Bowman
Boboco Ltd
ebowman [at] boboco [dot] ie
http://www.boboco.ie/ebowman/pubkey.pgp
+35318394189/+353872801532




Alexy Khrabrov
Joined: 2009-05-25,
User offline. Last seen 42 years 45 weeks ago.
Re: A Maven project for both Scala 2.7.5 and 2.8.0-SNAPSHOT?
Jorge -- I do it too now, couple of questions:

-- I moved branch master to Scala-2.7.5 and created another branch Scala-2.8.0-SNAPSHOT.  How do you name yours and how do you set remote on github?

-- Main problem: how do you avoid merging the actual intended differences back from one version of Scala to the other -- are we condemned to cherry-pick forever here?  I wish I could mark a patch "intended" and excluded from auto-merge...  That would replace preprocessing altogether.


BTW, using Maven profiles works fine, too.  Here's the relative sections in maven-yamlpom-plugin YAML -- see attached file.  Notice I set target-${scala.version} directory per Scala version so when I switch to it there's no need to recompile anything which didn't change.

Cheers,
Alexy
Alexy Khrabrov
Joined: 2009-05-25,
User offline. Last seen 42 years 45 weeks ago.
Re: A Maven project for both Scala 2.7.5 and 2.8.0-SNAPSHOT?
We can combine Git branches with Maven triggers to automate profile switching as follows: in the 2.7.5 branch, add a file Scala-2.7.5, and in the other add Scala-2.8.0-SNAPSHOT.  Then activate the appropriate Maven plugin based on the presence of that file.  The POM in YAML format is attached.  Now can simply mvn compile away regardless of the branch you're in, as long as they descend from one of the other language versioning ones.
Cheers,Alexy 

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland