Uploaded image for project: 'Maven'
  1. Maven
  2. MNG-5469

Maven should evaluate profiles per lifecycle

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Auto Closed
    • 3.0.5
    • None
    • Profiles
    • None

    Description

      Maven profiles are evaluated one time before running any lifecycle goals. This can lead to different behavior depending on whether the lifecycle goals are part of the same lifecycle model.

      Run the attached POM file:
      mvn clean compile
      The result is that if-file-missing runs, as expected since file.txt does not exist.

      Rerun the POM:
      mvn clean compile
      The result is that if-file-exists runs, but by the time the default lifecycle begins executing, which is after the clean lifecycle finishes, file.txt no longer exists.

      Furthermore, if you have performed your rerun of the POM as:
      mvn clean
      mvn compile
      The result would have been to execute if-file-missing, as expected.

      This means that Maven builds can have spurious results if the file the profile it is evaluating is located in the project build directory. Having Maven evaluate the necessary profiles at the beginning of each different lifecycle would alleviate this problem. Therefore, if evaluation was per lifecycle, the rerun would execute the clean lifecycle with if-file-exists and the default lifecycle with if-file-missing.

      Being able to accurately determine the existence of a file in the project build directory is important. My use case creates a throw-away keystore for signing jars. That keystore should be inside the project build directory because it needs to exist only for the lifetime of the build process and is not something that is intrinsic to the data being processed (ie. not essential to have in version control).

      Attachments

        1. pom.xml
          2 kB
          Karl Schaefer

        Activity

          People

            Unassigned Unassigned
            kschaefe Karl Schaefer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: