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

Properties defined in external file are not defined in POM file #39

Open
marioja opened this issue Jul 17, 2017 · 12 comments
Open

Properties defined in external file are not defined in POM file #39

marioja opened this issue Jul 17, 2017 · 12 comments

Comments

@marioja
Copy link

marioja commented Jul 17, 2017

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?

@tuxedo0801
Copy link

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

@marioja
Copy link
Author

marioja commented Mar 30, 2019

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

@marioja
Copy link
Author

marioja commented Mar 30, 2019

I would try Maven 3.6.0 to see if it works.

@GuptaMegha
Copy link

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

@flocsy
Copy link

flocsy commented Jun 11, 2020

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

@achimmihca
Copy link

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.

@javaspeak
Copy link

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.

@mipo256
Copy link

mipo256 commented May 27, 2023

@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.

@mipo256
Copy link

mipo256 commented May 27, 2023

@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.

@slawekjaranowski
Copy link
Member

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

@mipo256
Copy link

mipo256 commented Jul 3, 2023

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

@slawekjaranowski
Copy link
Member

I added #115 - please look.

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

8 participants