Maven2 property that indicates the parent directory

directory-maven-plugin
which option rightly gives the project's source directory?
how to get parent directory in maven
project.parent.basedir cannot resolve
maven properties
maven project root directory
maven resources-plugin parent directory
maven basedir

I have a multi-modules project, like this one:

main-project/
    module1/
    module2/
        sub-module1/
        sub-module2/
        sub-module3/
        ...
    module3/
    module4/
    ...

I need to define a set of properties (that are dependent of the environment on which I want to release my project) in Maven2. I will not use <properties> as there is lots of properties... Thus, I use the Properties Maven2 plugin.

The properties files are located in the main-project/ directory. How can I set the correct directory in the main pom.xml, in order to specify to any children where to find the properties file?

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-1</version>
    <executions>
        <execution>
            <phase>initialize</phase>
            <goals>
                <goal>read-project-properties</goal>
            </goals>
            <configuration>
                <files>
                    <file>???/env_${env}.properties</file>
                </files>
            </configuration>
        </execution>
    </executions>
</plugin>

If I set only <file>env_${env}.properties</file>, then when Maven2 compiles the first module, it will not find the main-project/env_dev.properties file. If I set <file>../env_${env}.properties</file>, then an error will be raised at the parent level, or at any sub-module level...

Try setting a property in each pom to find the main project directory.

In the parent:

<properties>
    <main.basedir>${project.basedir}</main.basedir>
</properties>

In the children:

<properties>
    <main.basedir>${project.parent.basedir}</main.basedir>
</properties>

In the grandchildren:

<properties>
    <main.basedir>${project.parent.parent.basedir}</main.basedir>
</properties>

Maven – Maven Getting Started Guide, project This is the top-level element in all Maven pom.xml files. artifactId This element indicates the unique base name of the primary artifact This is often used in Maven's generated documentation. properties This mvn clean. This will remove the target directory with all the build data before starting so that it is fresh. In Maven2 I've created the maven-archetype-webapp. I see the webapp and resource directory, Maven2 property that indicates the parent directory. 279.

At least in current maven version (3.6.0) you can make use of ${maven.multiModuleProjectDirectory}

Maven Model – Maven, The <project> element is the root of the descriptor. [+ path adjustment] + ( artifactId or project.directory property), or just parent value if project's In Maven 2, this was also specifying the minimum version of Maven required to build optional, String, Indicates the dependency is optional for use of this library. En d'autres termes, ${parent.base.directory} sera fixé correctement dans différents POM enfant. Remarque Vous ne devez pas utiliser ${parent.basedir} comme votre propriété définie par l'utilisateur parce qu'elle est la même que la propriété ${project.parent.basedir} par défaut de maven. Sinon, il erreur d'expression récursive dans maven.

Maven2 property that indicates the parent director-第3页回答, Maven2 property that indicates the parent director. 爷、活的狠高调 关注. 发布时间:2019-01-04 07:14. I have a multi-modules project, like this one: main-project/� Default value is: parent value [+ path adjustment] + (artifactId or project.directory property), or just parent value if project's child.project.url.inherit.append.path="false" inceptionYear: String: The year of the project's inception, specified with 4 digits. This value is used when generating copyright notices as well as being informational.

I've found a solution to solve my problem: I search the properties files using the Groovy Maven plugin.

As my properties file is necessarily in current directory, in ../ or in ../.., I wrote a small Groovy code that checks these three folders.

Here is the extract of my pom.xml:

<!-- Use Groovy to search the location of the properties file. -->
<plugin>
    <groupId>org.codehaus.groovy.maven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <version>1.0-rc-5</version>
    <executions>
        <execution>
            <phase>validate</phase>
            <goals>
                <goal>execute</goal>
            </goals>
            <configuration>
                <source>
                    import java.io.File;
                    String p = project.properties['env-properties-file'];
                    File f = new File(p); 
                    if (!f.exists()) {
                        f = new File("../" + p);
                        if (!f.exists()) {
                            f = new File("../../" + p);
                        }
                    }
                    project.properties['env-properties-file-by-groovy'] = f.getAbsolutePath();
            </source>
            </configuration>
        </execution>
    </executions>
</plugin>
<!-- Now, I can load the properties file using the new 'env-properties-file-by-groovy' property. -->
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-1</version>
    <executions>
        <execution>
            <phase>initialize</phase>
            <goals>
                <goal>read-project-properties</goal>
            </goals>
            <configuration>
                <files>
                    <file>${env-properties-file-by-groovy}</file>
                </files>
            </configuration>
        </execution>
    </executions>
</plugin>

This is working, but I don't really like it.

So, if you have a better solution, do not hesitate to post!

io.airlift : airbase : 93, the parent directory for e.g. the license resources. --> <!-- See http:// stackoverflow.com/questions/1012402/maven2-property-that-indicates-the- parent-directory� 3 Maven2 property that indicates the parent directory Nov Rarest. Teacher. Nov 16 '12. Stack Overflow. Questions; Jobs; Developer Jobs Directory; Salary

So the problem as I see it is that you can't get the absolute path to a parent directory in maven.

<rant> I've heard this talked about as an anti-pattern, but for every anti-pattern there is real, legitimate use case for it, and I'm sick of maven telling me I can only follow their patterns.</rant>

So the work around I found was to use antrun. Try this in the child pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <id>getMainBaseDir</id>
            <phase>validate</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <exportAntProperties>true</exportAntProperties>
                <target>
                    <!--Adjust the location below to your directory structure -->
                    <property name="main.basedir" location="./.." />
                    <echo message="main.basedir=${main.basedir}"/>
                </target>
            </configuration>
        </execution>
    </executions>
</plugin>

If you run mvn verify you should see something like this:

main:
     [echo] main.basedir=C:\src\parent.project.dir.name

You can then use ${main.basedir} in any of the other plugins, etc. Took me a while to figure this out, so hope it helps someone else.

AAPT2, dl.google.com/dl/android/maven2/com/android/tools/build/aapt2/ aapt2-version aapt2 compile path-to-input-files [ options ] -o output-directory / name and the name of its parent directory (the resource type and configuration). You can no longer indicate the type of a resource from the name attribute. maven 2 - Maven2 property that indicates the parent directory For example, I might want to run only the unit tests in the current working directory, rather than

airlift/airbase: Base POM for Airlift, You can use Maven properties in a pom.xml file or in any resource that is being processed build output. directory refers to the directory which contains all of these output directories. M2_HOME: Contains the Maven 2 installation directory. OpEd � OWASP � Resource � The Q&A Corner � The Week in Review � Video. Top. The 'root' directory of a project. For a simple project, this is identical to project.basedir. In a multi-module build, it should point at the root project. For a multi-module project, all other sub-modules must have this explicitly set to the root directory and therefore the following code

9.2. Maven Properties, means is that a build essentially configures a set of tasks and wires them project root gradle.properties file to leak into the buildSrc build and any builds the name of the build's root directory is used and the root project name is not The Maven Plugin used to publish the highly outdated Maven 2 metadata format. Hi to all mojo developers, based on the last days i had done some enhancements for the build-helper-maven-plugin to get some kind of information about the build environment like: username, java runtime, maven information, hostname etc. Currently i have got the impression that those changes i'm making to the build-helper-maven-plugin seemed not to be in the root intention of the plugin.

[PDF] Version 6.5.1, Top level configuration elements. Description (thumbs down). ${project.build. directory}/cargo/configurations/${containerId } In addition to this, properties can also be set using the Maven 2 / Maven 3 settings.xml file. See the Indicates if Cargo token replacement should be applied ( true ) when copying. Do not use this� This indicates to Maven that the dependency will be provided at run time by its container or the JDK, for example. Dependencies with this scope will not be passed on transitively, nor will they be bundled in an package such as a WAR, or included in the runtime classpath.

Comments
  • Just use ${maven.multiModuleProjectDirectory}
  • Were these pre-set properties removed? ${parent.basedir} no longer parses into anything in 3.0.4...
  • Yeah, this doesn't work. ${project.parent.basedir} evaluates to null.
  • I've had success with ${project.basedir}/.. but that really only works in multi-module projects that are in a strict directory hierarchy.
  • Sigh. Unbelievable, that Maven makes this so hard.
  • Like Jonathan above I have to use relative paths, but feel it is best to use the file.separator variable like this <main.basedir>${project.basedir}${file.separator}..</main.basedir>
  • Trying to find doc on this and it seems that this is intended as an internal usage, may be removed/changed in future MNG-6589
  • Make use of it how? -1
  • It is a property, you can use as you would do with others.
  • i'm not sure we should use this answer. According to this ticket it is internal and might go at any time. That's also why it's not documented anywhere. Still no clean solution
  • Don't put "test" for the phase. Caused me a variety of problems. Works great as shown above.
  • how do i pass it on to maven-surefire-plugin?
  • I don't know why this works (the extra ../) but this seems like the cleanest solution (I too was having issues with the checkstyle.xml config)