Giter VIP home page Giter VIP logo

obscure-maven-examples's Introduction

Examples with Obscure Uses of Maven Properties

See Stack Overflow question: Can ${...} properties appear in the <parent> section of a POM file?

While Maven's documentation claims that property values "are accessible anywhere within a POM", there are several tags that must be "constant", i.e. you cannot use property values in them. Today (2024/7/21) those restrictions are undocumented and unenforced.

Some restrictions can be discovered by trial-and-error, provided you pay attention to Maven's warnings.

To complicate matters, some properties are allowed in tags that are supposed to be constant. For instance, magic CI-friendly version properties can appear in <version> and <parent> -> <version>. There may be other exceptions as well; I can't find a definitive list of magic properties that Maven treats differently.

What's Here?

  • baseline: bog-standard parent-child project setup
  • name-contains-property: POM where name depends on a property defined in the same file
  • groupid-contains-property: POM where groupId depends on a property defined in the same file
  • groupid-contains-property-defined-in-parent: child's groupId depends on a property defined in the parent
  • parent-groupid-contains-property-asymmetric: child declares parent's groupId using a property; parent has a constant groupId
  • parent-groupid-contains-property-symmetric: child declares parent's groupId using a property; parent declares its own groupId the same way
  • parent-version-contains-property-symmetric: child declares parent's version using a property; parent declares its own version the same way
  • parent-version-contains-revision-property-asymmetric: child declares parent's groupId using the magic ${revision} property; parent has a constant groupId
  • parent-version-contains-revision-property-symmetric: child declares parent's groupId using the magic ${revision} property; parent declares its own groupId the same way

Observations (Maven 3.9.7, JDK 17)

Maven expects these tags to be constant:

  • <parent> and everything in it
  • <groupId>, <artifactId>, and <version>
  • maybe others (see Open Questions below)

A few notes about specific examples I think are interesting:

groupid-contains-property unexpectedly works. Maven issues a warning, but the effective POM has a groupId with the expanded property.

groupid-contains-property-defined-in-parent unexpectedly works. Maven issues a warning, but the effective POM has a groupId with the expanded property.

parent-groupid-contains-property-asymmetric fails. This is presumably expected, but it might be surprising because the child does contain enough information to fully resolve the parent's groupId.

parent-groupid-contains-property-symmetric unexpectedly works. When the groupIds are char-for-char equal before property expansion, Maven seems to accept it (with a warning). Note that this can produce a broken set of effective POMs if the parent and child do not agree on the value of the property.

parent-version-contains-revision-property-symmetric works but produces broken effective POMs. Maven issues no warnings in this case, but the final child POM references parent with version v2.0 while the final parent POM has version v1.0.

Open Questions

  • Can properties appear in <repositories>? (A repo might be needed to find the parent, and the parent might have the value for the property.)

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.