다중 모듈 메이븐 리액터 프로젝트의 루트 디렉토리 찾기
maven-dependency-plugin을 사용하여 다중 모듈 프로젝트의 모든 하위 모듈에서 전체 프로젝트의 루트 디렉토리에 상대적인 디렉토리로 EAR 파일을 복사하고 싶습니다.
즉, 내 레이아웃은 다음과 비슷하게 이름이 변경되었습니다.
to-deploy/
my-project/
ear-module-a/
ear-module-b/
more-modules-1/
ear-module-c/
ear-module-d/
more-modules-2/
ear-module-e/
ear-module-f/
...
그리고 모든 EAR 파일이 해당 모듈의 대상 디렉토리에서 복사되기를 원 my-project/../to-deploy하므로
to-deploy/
ear-module-a.ear
ear-module-b.ear
ear-module-c.ear
ear-module-d.ear
ear-module-e.ear
ear-module-f.ear
my-project/
...
다음과 같이 각 귀 모듈의 상대 경로로 할 수 있습니다.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>install</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>ear</type>
<outputDirectory>../../to-deploy</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
그러나 <outputDirectory>요소에 상대 경로를 지정하지 않고 싶습니다 . 나는 같은 것을 선호 ${reactor.root.directory}/../to-deploy하지만 이와 같은 것을 찾을 수 없습니다.
또한이 maven-dependency-plugin 구성을 상속하는 방법이 있으면 각 EAR 모듈에 대해 지정할 필요가없는 것이 좋습니다.
또한 루트 pom에서 사용자 지정 속성을 상속하려고 시도했습니다.
<properties>
<myproject.root>${basedir}</myproject.root>
</properties>
그러나 ${myproject.root}귀 모듈 POM에서 사용하려고 할 때 귀 모듈의 기반으로 ${basedir}해결됩니다.
또한 http://labs.consol.de/lang/de/blog/maven/project-root-path-in-a-maven-multi-module-project/를 찾았습니다. 여기서 각 개발자와 아마도 지속적인 통합 서버는 profiles.xml 파일에서 루트 디렉토리를 구성해야하지만 솔루션으로 간주하지 않습니다.
그렇다면 다중 모듈 프로젝트의 루트를 찾는 쉬운 방법이 있습니까?
Maven 3.3.1부터이 ${maven.multiModuleProjectDirectory}목적으로 사용할 수 있습니다 . ( https://stackoverflow.com/a/48879554/302789 감사합니다 )
편집 : 이것은 .mvn프로젝트의 루트에 폴더 가있을 때만 제대로 작동하는 것 같습니다 .
사용하다 ${session.executionRootDirectory}
기록을 ${session.executionRootDirectory}위해 Maven 3.0.3의 pom 파일에서 나를 위해 작동합니다. 이 속성은 실행중인 디렉터리가되므로 상위 프로젝트를 실행하면 각 모듈이 해당 루트 디렉터리의 경로를 가져올 수 있습니다.
이 속성을 사용하는 플러그인 구성을 부모 pom에 넣어 상속되도록했습니다. 부모 프로젝트에서 Maven을 실행할 것임을 알 때만 선택하는 프로필에서 사용합니다. 이렇게하면 하위 프로젝트에서 Maven을 실행할 때이 변수를 원하지 않는 방식으로 사용할 가능성이 적습니다 (변수가 부모에 대한 경로가 아니기 때문).
예를 들면
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-artifact</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<type>${project.packaging}</type>
</artifactItem>
</artifactItems>
<outputDirectory>${session.executionRootDirectory}/target/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
내 프로젝트에서 사용한 것은 하위 모듈 poms의 속성을 재정의하는 것입니다.
root: <myproject.root>${basedir}</myproject.root>
moduleA: <myproject.root>${basedir}/..</myproject.root>
other/moduleX: <myproject.root>${basedir}/../..</myproject.root>
이렇게하면 상대 경로가 계속 유지되지만 루트 모듈에서 플러그인을 한 번 정의 할 수 있으며 모듈은 myproject.root를 올바르게 대체하여이를 상속합니다.
이 특정 문제를 해결하는 maven 플러그인이 있습니다. directory-maven-plugin
선택한 속성에 프로젝트의 루트 경로를 할당합니다. highest-basedir문서에서 목표를 참조하십시오 .
예를 들면 :
<!-- Directory plugin to find parent root directory absolute path -->
<plugin>
<groupId>org.commonjava.maven.plugins</groupId>
<artifactId>directory-maven-plugin</artifactId>
<version>0.1</version>
<executions>
<execution>
<id>directories</id>
<goals>
<goal>highest-basedir</goal>
</goals>
<phase>initialize</phase>
<configuration>
<property>main.basedir</property>
</configuration>
</execution>
</executions>
</plugin>
그런 다음 ${main.basedir}부모 / 자식 pom.xml의 아무 곳에서나 사용 하십시오.
다른 사람들이 제안했듯이 directory-maven-plugin이 갈 길입니다. 그러나 https://stackoverflow.com/a/37965143/6498617에 설명 된대로 'directory-of'목표와 가장 잘 작동한다는 것을 알았습니다 .
I prefer that as using highest-basedir didn't work for me with a multi-module project, with nested multi-module poms. The directory-of goal lets you set a property to the path of any module in the whole project, including the root of course. It is also way better than ${session.executionRootDirectory}, because it always works, regardless of whether you build the root or a sub-module, and irrespective of the current working directory where you mvn from.
I encountered similar problem as i needed to copy files between projects. What Maven does is logical because it will keep the pom.xml installed in repository away from hard coded value.
My solution was to put copied dir in a Maven artifact, then employ Ant to extract/copy
The following small profile worked for me. I needed such a configuration for CheckStyle, which I put into the config directory in the root of the project, so I can run it from the main module and from submodules.
<profile>
<id>root-dir</id>
<activation>
<file>
<exists>${project.basedir}/../../config/checkstyle.xml</exists>
</file>
</activation>
<properties>
<project.config.path>${project.basedir}/../config</project.config.path>
</properties>
</profile>
It won't work for nested modules, but I'm sure it can be modified for that using several profiles with different exists's. (I have no idea why there should be "../.." in the verification tag and just ".." in the overriden property itself, but it works only in that way.)
I'm not aware of a "nice" way to find the root of a multi-module project. But you can maybe improve a bit your current approach.
A first alternative would be to create an additional module directly under the root project, to declare all EARs as dependencies in it and to use dependency:copy-dependencies to copy the dependencies of the module to the to-deploy directory (relatively). Yes the path would still be relative but since the dependency plugin configuration would be centralized, I don't find it that annoying.
A second alternative would be to use the Maven Assembly Plugin instead of the Maven Dependency Plugin to create a distribution using the dir format (this will create a distribution in a directory). This is actually what I would do.
Another solution would be to use an ant task to write "rootdir=${basedir}" to a target/root.properties in the root project, and then use the Properties Plugin to read that file back in. I haven't tried it myself, but I guess it should work..?
so that: somewhere in properties of some parent Project I've the file which i need to relate later, what's why i need absolute path on it everywhere. So, i get it with help of groovy:
<properties>
<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);
}
}
// setting path together with file name in variable xyz_format
project.properties['xyz_format'] =f.getAbsolutePath()
+ File.separator
+ "abc_format.xml";
</source>
</properties>
and then:
<properties>
<snapshots>http://localhost:8081/snapshots<snapshots>
<releases>http://localhost:8081/releases</releases>
<sonar>jdbc:oracle:thin:sonar/sonar@localhost/XE</sonar>
<sonar.jdbc.username>sonar</sonar.jdbc.username>
<format.conf> ${xyz_format}</format.conf> <---- here is it!
</properties>
it works!
You can go with something like this. Note, that you have to define two profiles - one which will be activated for the root directory and one for children. Obviously this assumes children will have the same structure but this can be easily adapted.
<profiles>
<profile>
<id>root-dir</id>
<activation>
<file>
<exists>${basedir}/lib</exists>
</file>
</activation>
<properties>
<project.libdir>${basedir}/lib</project.libdir>
</properties>
</profile>
<profile>
<id>child-dir</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<project.libdir>${basedir}/../../lib</project.libdir>
</properties>
</profile>
</profiles>
'IT TIP' 카테고리의 다른 글
| fromPromise가 Observable 유형에 존재하지 않습니다. (0) | 2020.11.26 |
|---|---|
| Xcode 누락 지원 파일 iOS 12.2 (16E227) (0) | 2020.11.26 |
| 복사 할당 연산자가 참조 / 상수 참조를 반환해야하는 이유는 무엇입니까? (0) | 2020.11.26 |
| 다른 컨트롤러에서 부분보기 렌더링 (0) | 2020.11.26 |
| make : 규칙 호출 규칙 (0) | 2020.11.26 |