Can I use a custom lifecycle defined in a multi-module project? - maven

I have a project that has a complex lifecycle, so a custom lifecycle makes sense. However, I would like to be able to have the lifecycle defined in a plugin that is in the same multi-module build. The plugin just defines the custom lifecycle (in a components.xml).
apollo-server-parent
- apollo-server-lifecycle-plugin
- src/main/resources/META-INF/plexus/components.xml (defines apollo-server-product)
- ApolloServer
- pom.xml
...
<packaging>apollo-server-product</packaging>
...
<plugin>
<groupId>ca.nanometrics.apollo</groupId>
<artifactId>apollo-server-lifecycle-plugin</artifactId>
<version>${project.parent.version}</version>
<extensions>true</extensions>
</plugin>
However, if I do this, maven won't build because it cannot find the apollo-server-lifecycle-plugin because it has not been built yet while building the reactor. Any ideas on how to work around this? Do I have to define the plugin in a separate project?
An example of the error I get:
[ERROR] Some problems were encountered while processing the POMs:
[ERROR] Unresolveable build extension: Plugin ca.nanometrics.apollo:apollo-server-plugin:4.0.0-SNAPSHOT or one of its dependencies could not be resolved: Could not find artifact ca.nanometrics.apollo:apollo-server-plugin:jar:4.0.0-SNAPSHOT in releases (http://.../nexus/content/groups/public) #
[ERROR] Unknown packaging: apollo-server-product # ca.nanometrics.apollo:ApolloServer:[unknown-version], /opt/atlassian/pipelines/agent/build/ApolloServer/pom.xml, line 10, column 14
#
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project ca.nanometrics.apollo:ApolloServer:4.0.0-SNAPSHOT (/opt/atlassian/pipelines/agent/build/ApolloServer/pom.xml) has 2 errors
[ERROR] Unresolveable build extension: Plugin ca.nanometrics.apollo:apollo-server-plugin:4.0.0-SNAPSHOT or one of its dependencies could not be resolved: Could not find artifact ca.nanometrics.apollo:apollo-server-plugin:jar:4.0.0-SNAPSHOT in releases (http://.../nexus/content/groups/public) -> [Help 2]
[ERROR] Unknown packaging: apollo-server-product # ca.nanometrics.apollo:ApolloServer:[unknown-version], /opt/atlassian/pipelines/agent/build/ApolloServer/pom.xml, line 10, column 14

If I am not getting you wrong here -
You want to build ApolloServer module, which uses
apollo-server-lifecycle-plugin which is also a module of your
project.
Current project structure being :
apollo-server-parent
- apollo-server-lifecycle-plugin
- ApolloServer
From the multi-module guide, one simple way of doing this could be making sure that apollo-server-lifecycle-plugin is build prior to the ApolloServer module always. Easiest way to do that could be to include the dependency of apollo-server-lifecycle-plugin in ApolloServer(pom.xml) which would make sure the Reactor sorting builds plugin first.
a plugin dependency on another module in the build

Related

Maven Build Compilation Error: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.8:analyze-dep-mgt

I have a multi-module Maven project in one root project I just want to add another maven module in the root project which contains many module, so after calling the parent from the pom.xml child I get the following error:
parent pom:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.8:analyze-dep-mgt (default) on project calender: Found Dependency errors.
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.8:analyze-dep
-mgt (default) on project calender: Found Dependency errors.
analyze-dep-mgt is a mojo which detects whenever there are dependency mismatches during the final resolution of the build. (https://maven.apache.org/plugins/maven-dependency-plugin/analyze-dep-mgt-mojo.html)
There is likely to be a problem with your dependencies. Check this documentation for more info on how to structure your poms. (https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html)
I recently had this error when adding a new dependency in which a transitive dependency was causing the same goal fail. Using an older version of the dependency resolved the issue.

Issue while creating eclipse p2 repository using maven tycho plugin

Project structure
com.abc.parent - parent pom
Contains all the plugins required for the modules. And the module execution list.
com.abc.p2 - master P2 project - eclipse repository
Contains the category.xml file with the information related to the below mentioned eclipse plugins.
com.abc.common - eclipse plugin
com.abc.person - eclipse plugin
What we want to achieve
We are introducing Maven for the first time for these project . We want to create a P2 repository using Maven ( mostly by using maven tycho plugin or any other standard available plugins ). Also , we wish to publish this repository to a site location.
What we tried until now
Case 1:
Approach - We used Maven Tycho plugin and added the packaging as "eclipse-repository" for the com.abc.p2 project.
We have following plugins in the pom.xml files
We are using Maven tycho plugin with version - 0.24.0
Maven tycho plugin. maven-p2-repository , tycho-packaging plugin , maven-osgi-plugin
Errors -
[ERROR] Unknown packaging: eclipse-repository # line 6, column 14
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[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 rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildin
gException
Case 2 :
Approach - We used Maven-p2-plugin in order to create P2 repository .
Errors -
We were able to generate the P2-repository structure in the target folder of the master project, , but it failed to package all the dependent modules in the p2-repository.
Next steps suggestions
Request you to kindly assist and suggest , if we are on the right track in order to achieve our goal . Also let me know in case any changes required to my approach and any more additional things to be implemented.
For tycho to work you need an extensions.xml file in a .mvn folder in the root of your project (where the root pom.xml is) with the following contents:
<extensions>
<extension>
<groupId>org.eclipse.tycho.extras</groupId>
<artifactId>tycho-pomless</artifactId>
<version>0.26.0</version>
</extension></extensions>
As you can see in the excellent Vogella tutorial
I would suggest using the tycho-p2-repository plugin.
In case 1, the maven repository plugin does not know the packaging "eclipse-repository" as that packaging is defined by tycho. I suggest simply leaving the maven-packaging plugin out of your pom and let tycho apply its defaults.
One helpful tip: Tycho does not include all dependencies, even though that's normal and desired maven behaviour. As maven does not "see" tycho (so manifest-derived) dependencies, they are not included.
You can override this behaviour by setting to true:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<includeAllDependencies>true</includeAllDependencies>
</configuration>
</plugin>

Spring Batch Admin ... Problems Building 1.3.0 RELEASE

I pulled the latest Spring Batch Admin-1.3.0-RELEASE and am trying to build and deploy. In eclipse I imported then as Maven Projects. I try to build with maven and it fails unless I remove these lines from the pom.xml files.
<plugin>
<groupId>com.springsource.bundlor</groupId>
<artifactId>com.springsource.bundlor.maven</artifactId>
</plugin>
or else I get an error
[ERROR] Failed to execute goal com.springsource.bundlor:com.springsource.bundlor.maven:1.0.0.RELEASE:bundlor (bundlor-transform) on project spring-batch-admin-resources: Execution bundlor-transform of goal com.springsource.bundlor:com.springsource.bundlor.maven:1.0.0.RELEASE:bundlor failed: Plugin com.springsource.bundlor:com.springsource.bundlor.maven:1.0.0.RELEASE or one of its dependencies could not be resolved: The following artifacts could not be resolved: org.objectweb.asm:com.springsource.org.objectweb.asm.tree:jar:3.1.0, org.objectweb.asm:com.springsource.org.objectweb.asm.commons:jar:3.1.0, org.objectweb.asm:com.springsource.org.objectweb.asm:jar:3.1.0: Could not find artifact org.objectweb.asm:com.springsource.org.objectweb.asm.tree:jar:3.1.0 in internal-repository (http://nexus-server:8082/nexus/content/groups/released) -> [Help 1]
You would have to add spring repositories in your pom.xml to tell maven to look there as well while looking up for dependencies as mentioned here

maven archetype assembly failure on dashclassifier

i have a archetype project which has a assembly.xml inside archetype-resources. it all worked fine till i had to change this
<unpack>false</unpack>
<outputFileNameMapping>${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension}</outputFileNameMapping>
in <dependencyset>.
For some reason the clean install gives an error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.1:integration-
test (default-integration-test) on project jetxyz:
[ERROR] Archetype IT 'basic' failed: org.apache.maven.archetype.exception.ArchetypeGenerationFailure: Error merging velocity templates: Encountered "?}." at line 15, column 110 of archetype-resources/assembly.xml
[ERROR] Was expecting one of:
[ERROR] "}" ...
[ERROR] <DOT> ...
when I use the same changes on an actual project assembly.xml this complies fine, gives issue only in the archetype project. Which is strange. I was expecting Maven to not worry about archetype-resources at all.
edit
default value of outputFileNameMapping is ${artifact.artifactId}-${artifact.version}${dashClassifier?}.${artifact.extension} . All I did was change version to baseVersion. dependencySet

m2eclipse: Multi-module and parent build exception

I am new to m2eclipse, and I created a dummy java project (mytest4) and checked enable dependency management, after that, the plugin created a pom.xml file. I manually added parent information, such as groupId, artifactId and version, etc. to the dummy project. Then I added modules to the parent project, and the parent projectType is pom not jar. However, when I build using clean install, I get an error:
[DEBUG] Extension realms for project com.multimod:myproject:pom:0.0.1-SNAPSHOT: (none)
[DEBUG] Looking up lifecyle mappings for packaging pom from ClassRealm[plexus.core, parent: null]
[ERROR] The build could not read 1 project ->
[Help 1]org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[ERROR] Child module C:\workspace\myproject\mytest4 of C:\workspace\myproject\pom.xml does not exist #
[ERROR] The project com.multimod:myproject:0.0.1-SNAPSHOT(C:\workspace\myproject\pom.xml) has 1 error
[ERROR] Child module C:\workspace\myproject\mytest4 of C:\workspace\myproject\pom.xml does not exist
I don't understand C:\workspance\myproject\pom.xml does not exist.
Could you give some hints?
Thank you.
You probably have to set the relative path to you parent pom file in the mytest4 pom file. The default is ../pom.xml hence your path C:\workspace\myproject\pom.xml.
As to your sub question in the comment. Right click on the project en select Configure > Convert to Maven Project

Resources