Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build model fails if a systemPath dependency uses ${env.XXXX} values #324

Open
drivera-armedia opened this issue Oct 19, 2022 · 1 comment

Comments

@drivera-armedia
Copy link

Hi! I'm using something similar to this:

<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

  <!-- ... -->

  <groupId>my.group.id</groupId>
  <artifactId>my-artifact-name</artifactId>
  <version>${revision}</version>
  <packaging>pom</packaging>

  <!-- ... -->

  <dependencyManagement>
    <dependencies>

      <!-- ... -->

      <dependency>
         <groupId>dependency.group.id</groupId>
          <artifactId>dependency-artifact</artifactId>
          <version>${dependency.version}</version>
         <scope>system</scope>
          <systemPath>${env.TOOL_INSTALL_PATH}/lib/main-tool.jar</systemPath>
      </dependency>

      <!-- ... -->

    </dependencies>
  </dependencyManagement>

  <!-- ... -->

  <build>
    <plugins>

      <!-- ... -->

      <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>flatten-maven-plugin</artifactId>
          <version>1.3.0</version>
          <configuration>
            <updatePomFile>true</updatePomFile>
            <flattenMode>resolveCiFriendliesOnly</flattenMode>
          </configuration>
          <executions>
            <execution>
              <id>flatten.process-resources</id>
              <phase>process-resources</phase>
              <goals>
                <goal>flatten</goal>
              </goals>
            </execution>
            <execution>
              <id>flatten.clean</id>
              <phase>clean</phase>
              <goals>
                <goal>clean</goal>
              </goals>
            </execution>
          </executions>
        </plugin>

      <!-- ... -->

    </plugins>

    <!-- ... -->

  </build>

  <!-- ... -->

</pom>

I'm trying to use the flatten plugin to resolve the ${revision} variable prior to artifact deployment for downstream consumption, as mandated by Maven's CI-Friendly practices. However, the systemPath dependency isn't resolved properly. The environment variable is set correctly, and the build works perfectly when not using the flatten plugin - albeit the artifacts produced aren't consumable from a repository due to the use of <version>${revision}</version> to allow easy manipulation of the project's version.

This is the exception dump I get from using mvn -e:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:flatten-maven-plugin:1.3.0:flatten (flatten.process-resources) on project my-artifact-name: 1 problem was encountered while building the effective model for my.group.id:my-artifact-name:1.0.0
[ERROR] 'dependencyManagement.dependencies.dependency.systemPath' for dependency.group.id:dependency-artifact:jar must specify an absolute path but is ${env.TOOL_INSTALL_PATH}/lib/main-tool.jar @ 

    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:375)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:351)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:171)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:163)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoExecutionException: 1 problem was encountered while building the effective model for my.group.id:my-artifact-name:1.0.0
[ERROR] 'dependencyManagement.dependencies.dependency.systemPath' for dependency.group.id:dependency-artifact:jar must specify an absolute path but is ${env.TOOL_INSTALL_PATH}/lib/main-tool.jar @ 

    at org.codehaus.mojo.flatten.FlattenMojo.createEffectivePom (FlattenMojo.java:986)
    at org.codehaus.mojo.flatten.FlattenMojo.createFlattenedPom (FlattenMojo.java:594)
    at org.codehaus.mojo.flatten.FlattenMojo.execute (FlattenMojo.java:422)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:370)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:351)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:171)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:163)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.model.building.ModelBuildingException: 1 problem was encountered while building the effective model for my.group.id:my-artifact-name:1.0.0
[ERROR] 'dependencyManagement.dependencies.dependency.systemPath' for dependency.group.id:dependency-artifact:jar must specify an absolute path but is ${env.TOOL_INSTALL_PATH}/lib/main-tool.jar @ 

    at org.apache.maven.model.building.DefaultModelProblemCollector.newModelBuildingException (DefaultModelProblemCollector.java:197)
    at org.apache.maven.model.building.DefaultModelBuilder.build (DefaultModelBuilder.java:568)
    at org.apache.maven.model.building.DefaultModelBuilder.build (DefaultModelBuilder.java:454)
    at org.apache.maven.model.building.DefaultModelBuilder.build (DefaultModelBuilder.java:267)
    at org.codehaus.mojo.flatten.ModelBuilderThreadSafetyWorkaround.build (ModelBuilderThreadSafetyWorkaround.java:134)
    at org.codehaus.mojo.flatten.FlattenMojo.createEffectivePom (FlattenMojo.java:982)
    at org.codehaus.mojo.flatten.FlattenMojo.createFlattenedPom (FlattenMojo.java:594)
    at org.codehaus.mojo.flatten.FlattenMojo.execute (FlattenMojo.java:422)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:370)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:351)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:171)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:163)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)

Per other tickets I've found, and the integration test system-scope-dep-variable, variable expansion should work on systemPath dependencies. However, it seems that environment variable expansion isn't working properly.

Is there a workaround that I've not found? Is this a fixable bug?

I'm aware that systemPath dependencies are on their way out and we're trying to grapple with how to properly live in that world when it comes ... for now, however, it makes sense to use it for this specific project given that the dependency in question is a legacy library that isn't and will never be available via a Maven repository (long story, trust me on this).

Thoughts?

Cheers!

@mpsanchis
Copy link

Hi all!

I'm also interested in this, but I saw no activity or labelling for this issue. I found this other plugin that does the job for me: https://central.sonatype.com/artifact/com.sap.prd.mobile.ios.maven.plugins/resolve-pom-maven-plugin

but I'd rather rely on the flatten maven plugin, which seems to be the recommended way, and it's open source.

Is there a way to upvote this?

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants