mojohaus / properties-maven-plugin

The Properties Maven Plugin

Home Page:https://www.mojohaus.org/properties-maven-plugin/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Properties defined in external file are not defined in POM file

marioja opened this issue · comments

I have the following pom file:

<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>test.properties</groupId>
  <artifactId>properties</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
	<scm>
		<connection>scm:svn:http://mysvnserver/repo</connection>
	</scm>
	<build>
		<plugins>
			<plugin>
			    <groupId>org.codehaus.mojo</groupId>
			    <artifactId>properties-maven-plugin</artifactId>
			    <version>1.0.0</version>
				<executions>
					<execution>
						<phase>initialize</phase>
						<goals>
							<goal>read-project-properties</goal>
						</goals>
						<configuration>
							<files>
								<file>maven.build.properties</file>
							</files>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-scm-plugin</artifactId>
				<version>1.9.4</version>
				<executions>
					<execution>
						<id>ConfigScripts</id>
						<phase>generate-sources</phase>
						<configuration>
							<checkoutDirectory>${workspaces}/${workspace}/${project.build.plugins[1].executions[0].id}</checkoutDirectory>
							<scmVersion>${ConfigScripts.branch}/${project.build.plugins[1].executions[0].id}</scmVersion>
							<scmVersionType>branch</scmVersionType>
						</configuration>
						<goals>
							<goal>${SCM.goals}</goal>
						</goals>
					</execution>
					<execution>
						<id>profile</id>
						<phase>generate-sources</phase>
						<configuration>
							<checkoutDirectory>${workspaces}/${workspace}/${project.build.plugins[1].executions[1].id}</checkoutDirectory>
							<scmVersion>${profile.branch}/${project.build.plugins[1].executions[1].id}</scmVersion>
							<scmVersionType>branch</scmVersionType>
						</configuration>
						<goals>
							<goal>${SCM.goals}</goal>
						</goals>
					</execution>
					<execution>
						<id>Context</id>
						<phase>generate-sources</phase>
						<configuration>
							<checkoutDirectory>${workspaces}/${workspace}/${project.build.plugins[1].executions[2].id}</checkoutDirectory>
							<scmVersion>${Context.branch}/${project.build.plugins[1].executions[2].id}</scmVersion>
							<scmVersionType>branch</scmVersionType>
						</configuration>
						<goals>
							<goal>${SCM.goals}</goal>
						</goals>
					</execution>
					<execution>
						<id>Libraries</id>
						<phase>generate-sources</phase>
						<configuration>
							<checkoutDirectory>${workspaces}/${workspace}/${project.build.plugins[1].executions[3].id}</checkoutDirectory>
							<scmVersion>${Libraries.branch}/${project.build.plugins[1].executions[3].id}</scmVersion>
							<scmVersionType>branch</scmVersionType>
						</configuration>
						<goals>
							<goal>${SCM.goals}</goal>
						</goals>
					</execution>
					<execution>
						<id>abcdUtilsJava</id>
						<phase>generate-sources</phase>
						<configuration>
							<connectionUrl>scm:svn:${shared.url}</connectionUrl>
							<checkoutDirectory>${workspaces}/${workspace}/${project.build.plugins[1].executions[4].id}</checkoutDirectory>
							<scmVersion>${abcdUtilsJava.branch}/${project.build.plugins[1].executions[4].id}</scmVersion>
							<scmVersionType>branch</scmVersionType>
						</configuration>
						<goals>
							<goal>${SCM.goals}</goal>
						</goals>
					</execution>
					<execution>
						<id>abcddrs</id>
						<phase>generate-sources</phase>
						<configuration>
							<connectionUrl>scm:svn:${abcddrs.url}</connectionUrl>
							<checkoutDirectory>${workspaces}/${workspace}/${project.build.plugins[1].executions[5].id}</checkoutDirectory>
							<scmVersion>${abcddrs.branch}/${project.build.plugins[1].executions[5].id}</scmVersion>
							<scmVersionType>branch</scmVersionType>
						</configuration>
						<goals>
							<goal>${SCM.goals}</goal>
						</goals>
					</execution>
					<execution>
						<id>eclipse_pref.epf</id>
						<phase>generate-sources</phase>
						<configuration>
						<!-- http://cbsasvnserver1/apps/dcscripts/tags/devtags/WORKSPACE_SCRIPTS_B_ECLIPSE_V01/workspace/scripts/build/shared/import/eclipse_pref.epf -->
							<connectionUrl>scm:svn:${prefs.url}</connectionUrl>
							<checkoutDirectory>${workspaces}/${workspace}/abcddrs/src/prefs</checkoutDirectory>
							<scmVersion>${prefs.tag}</scmVersion>
							<scmVersionType>tag</scmVersionType>
						</configuration>
						<goals>
							<goal>${SCM.goals}</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
	<!-- <properties>
		<SCM.goals>checkout</SCM.goals>
	</properties> -->
</project>

When I run it I get this output:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building properties 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.313 s
[INFO] Finished at: 2017-07-17T11:37:41-04:00
[INFO] Final Memory: 6M/123M
[INFO] ------------------------------------------------------------------------
[ERROR] Could not find goal '${SCM.goals}' in plugin org.apache.maven.plugins:maven-scm-plugin:1.9.4 among available goals status, branch, validate, checkin, diff, update, add, remove, unedit, bootstrap, checkout, tag, edit, check-local-modification, list, changelog, help, export, update-subprojects -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoNotFoundException

If I uncomment the SCM.goals property definition in the POM file, all runs fine. I remember reading somewhere about properties contributed by the properties maven plugin can only be used in configuration (although it seems to work in my executions). Can someone explain why this is the case and whether there is a way to make this work?

commented

Same issue here :-(
Did you find a solution for this? @marioja

It has been so long and I do not recall but I think no solution was found

I would try Maven 3.6.0 to see if it works.

commented

I am facing the same issue in Maven 3.6.0, any updates?

Still no solution for this? It's clearly a use-case many developers face.

I have the same issue.

Trying to define a path in a properties file: myDir=my/cool/directory
Cannot use this property in pom.xml

    <testResource>
        <directory>${project.basedir}/${myDir}</directory>
    </testResource>

It works if I specifying the custom property in <properties> tag of the pom.xml. But I need it in a separate file.

I have the same issue.

Trying to define a path in a properties file: myDir=my/cool/directory Cannot use this property in pom.xml

    <testResource>
        <directory>${project.basedir}/${myDir}</directory>
    </testResource>

It works if I specifying the custom property in <properties> tag of the pom.xml. But I need it in a separate file.

Did anyone resolve this - what is the point of the properties maven plugin if you cannot read properties from it? - I think am missing something.

@marioja @tuxedo0801 @javaspeak @GuptaMegha @flocsy @achimmihca
Guys, that plugin is not goin to solve this problem. The problem is that the DOM of POM is parsed before any build. So when this plugins of yours are parsed, at this time. there is no such property defined as you specified in the <goal> tag, so maven just thinks ${SCM.goal} is the name. The same stuff would happen with dependencies versions for example.

To solve this problem you can provide properties to maven via command line, like -DSCM.goal in your case. Then the maven will parse POM, and SCM.goal or whatever property you want will be already defined before build, so you will have ${SCM.goal} value substituted.

@marioja Please, close this issue. It is not the plugin fault. I will raise the issue about post-POM-parsing variables interpolation in Maven Jira.

@Mikhail2048 did you create issue in Maven jira? Can you share issue number?

@slawekjaranowski Yep, I have already submitted the Jira ticket. here it is.

I added #115 - please look.