Code Monkey home page Code Monkey logo

scala-cross-maven-plugin's Introduction

scala-cross-maven-plugin

This plugin enables you to publish "clean" POM files after interpolating values for the Scala version and Scala binary version.

Why

A common way to vary Scala binary versions is to use Maven profiles, declaring one profile for each binary version you want to cross compile to. Then you run Maven once for each binary version, activating the appropriate profile, to build and deploy artifacts.

However, the published POMs end up not working so well:

  • Maven doesn't like it when you use variable substitution in artifact IDs (and will warn you of this on startup).
  • The published POMs will require consumers to know about (and duplicate) the use of your profile IDs in order to interpolate the correct variables.
  • Many developers set one of the Scala-version profiles to be activated by default, which:
    • can cause confusing (silent) failures if a new developer runs Maven without explicitly specifying the desired profile.
    • can cause confusing issues if the set of property names in each Scala-version profile is not exactly the same.
  • If one of the Scala-version profiles is not set as activated by default, often default values for the Scala version and binary/compat version are specified outside the profile, which can cause similar problems to those outlined in the previous point.

Other Resources / Prior Art

  • There's a fine discussion of the perils of using Maven for Scala builds by Ryan Williams of Hammer Lab.
  • The flatten-maven-plugin almost does what we want, but is difficult to configure so that it makes the fewest modifications necessary to the POM file.

Usage

To make this work, ideally your POM and build should conform to a convention like so:

  • You have a separate profile for each Scala binary/compat version, named like scala-2.11, scala-2.12, etc.
  • None of these scala-* profiles are active by default.
  • You use properties named scala.version and scala.binary.version (or scala.compat.version) to determine which Scala versions to use.
  • You have artifact (and possibly group) IDs that require the binary/compat version to be interpolated into them.
  • You do not put defaults for the above properties in the POM's main properties section. (Note: Some IDEs, like IntelliJ IDEA, won't work properly without a default for scala.binary.version, even if you properly select the correct profile to use. Adding a default for that property seems to work ok.)

If you've fulfilled the above, you can just do the following:

<build>
  <plugins>
    ..
    <plugin>
      <groupId>org.spurint.maven.plugins</groupId>
      <artifactId>scala-cross-maven-plugin</artifactId>
      <version>{see tags for latest version}</version>
      <executions>
          <execution>
              <id>rewrite-pom</id>
              <goals>
                  <goal>rewrite-pom</goal>
              </goals>
          </execution>
      </executions>
    </plugin>
    ..
  </plugins>
</build>

When you run your build, pass -Pscala-2.12 (or whichever profile you want) to Maven, and things will just work.

In reality, the plugin will take any properties defined in your Scala-version profile and interpolate them into group and artifact IDs in the rest of the POM.

For reference, here's an example of some profiles you might use:

<profiles>
  <profile>
    <id>scala-2.11</id>
    <properties>
      <scala.binary.version>2.11</scala.binary.version>
      <scala.version>2.11.12</scala.version>
    </properties>
  </profile>
  <profile>
    <id>scala-2.12</id>
    <properties>
      <scala.binary.version>2.12</scala.binary.version>
      <scala.version>2.12.10</scala.version>
    </properties>
  </profile>
</profiles>

Configuration

There are a few settings you can use to tailor execution to your environment.

Name Default Description
rewrittenPomPath ${project.build.directory}/.scala-cross-pom.xml Full path to where to write the interpolated POM file.
scalaProfilePrefix scala- Prefix for profile names used to for scala cross-compilation. The assumed suffix is the Scala binary version.
scalaProfileId (none) Alternatively, you can specify the full name of the profile to use (scalaProfilePrefix will be ignored).
scrubProfiles false Before writing the final POM, remove all detected Scala-version profiles.

scala-cross-maven-plugin's People

Contributors

dependabot[bot] avatar kelnos avatar rdesgroppes avatar scala-steward avatar sullis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

scala-cross-maven-plugin's Issues

Build all profiles in one run

What is the correct way to build all profiles in one run? Say I have a project with 2.11 and 2.12 support and want to publish both versions to maven central. What is the correct way to do this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.