3

I'm trying to add a system scoped dependency to my POM. The trick is that I do not have the systemPath. Instead, I have a path to a properties file that contains a property that I can use as the path.

I've tried to use the properties-maven-plugin to deal with this, but it seems that the system dependency gets resolved before the plugin runs, and so the property that I'm trying to define is not available soon enough.

Here's the section of my POM:

<profiles>
    <profile>
        <id>dylink</id>
        <dependencies>
            <dependency>
                <artifactId>outside-lib</artifactId>
                <groupId>com.foo</groupId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>${outsidelib.location}/outside-lib.jar</systemPath>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>properties-maven-plugin</artifactId>
                    <version>1.0-alpha-2</version>
                    <executions>
                        <execution>
                            <phase>initialize</phase>
                            <goals>
                                <goal>read-project-properties</goal>
                            </goals>
                            <configuration>
                                <files>
                                    <file>C:\path\to\file.properties</file>
                                </files>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

And I run something like mvn -P dylink compile and get told that my systemPath is invalid because it's not an absolute path. (The property contains an absolute path)

Alternatively, is there any other way I can do this? I need to be able to query the host system for the location of the system-scope dependency. It won't work to just hard-code the path into the POM.

Nathaniel Waisbrot
  • 19,061
  • 3
  • 65
  • 86

2 Answers2

5

It is not possible. In order to execute plugins, maven needs to have everything required 'downloaded' in the local repository. It needs to be sure of the dependencies' versions, which are often defined in properties. Hence, it needs to start by finding the property values before downloading all that is missing, before executing plugins. You want the plugins to be executed before property values are defined...

I guess the properties plugins adds extra property values when executed, but that happens after the maven dependency check...

Jérôme Verstrynge
  • 51,859
  • 84
  • 263
  • 429
  • Eventually, a 'cleaner' solution is to ask the producers of your dependency to put it in a publicly accessible maven repository of their own, and add that repository in your pom.xml. Maven will search it for your dependency. Sonatype.org offers such services... – Jérôme Verstrynge Apr 11 '13 at 22:06
1

I am guessing here, but if you have to specify it dynamically it is because you have to run it in another environment. What you can do is still use a maven property but you can pass it to the command line as an argument :

mvn -Doutsidelib.location=myAbsolutePathReadFromPropertyFileJustBefore

And of course, you would have to read the property file or set an env variable before running your maven command.

benzonico
  • 10,145
  • 5
  • 36
  • 48
  • A good idea to simplify the problems. I tried that and Maven still doesn't like the variable in the systemPath. I gave up and made a wrapper script that installs the system jar into the local repository before running Maven, and that's working. I'm still puzzled why I couldn't get this to work, though. – Nathaniel Waisbrot Mar 22 '13 at 20:00