Maven execute plugin specified in pom - maven

I am very new to Maven, and I am facing the situation that I need to execute plugin specified in pom.xml which generates java classes from xsd. This plugin is specified in build section so I need to compile all the code before it is triggered. Is there some way how to trigger the plugin with all its configuration specified in pom.xml directly?
I have searched online and the suggested way was to call
mvn org.apache.cxf:cxf-xjc-plugin:2.6.1:xsdtojava
(this is my plugin), but I am getting error Must specify xsdOptions, so from my understanding it is just calling the plugin without he config specified in pom.xml.
If someone could help me, it would be great. I can not edit the pom.xml!

Related

maven 3.6.3 not able to execute `project.remotePluginRepositories`

I have been using maven 3.0.4 and one of our plugin's goal is using project.remotePluginRepositories. I have to now use maven 3.6.3 and I keep getting errors of value not found of project.remotePluginRepositories. The configuration of my goal is configured as:
<pluginRepos default-value="${project.remotePluginRepositories}"/>
I have also tried changing to the following, but I am still getting errors:
<pluginRepos>${project.remotePluginRepositories}</pluginRepos>
This pom.xml is in the child folder of the main folder with its pom.xml file.
I also can't find where project.remotePluginRepositories is defined so I also don't know how exactly the value is defined in XML format. Need help. Thanks

How to run just generate goal from swagger codegen maven plugin

I am using the swagger codegen maven plugin to generate a server stub from a swagger spec. If I run mvn compile then it generates properly and compiles the project. However, sometimes I want to run just the generate.
Specifically, I'd like to avoid both compiling the whole project and also running another plugin (checkstyles) which runs in the validate phase. Ideally, I'd like to generate the generated classes from the swagger spec and compile those classes but not the project as a whole.
The use case here is that while developing I may need to update the spec and re-generate at points when the project as a whole isn't valid (or won't be, with the new spec). I've read that you can use "prefix:goal". I've tried the following, but none work:
mvn swagger-codegen-maven-plugin:generate
mvn swagger-codegen:generate
mvn swagger:generate
mvn codegen:generate
It gives (e.g.)
No plugin found for prefix 'codegen' in the current project and in the
plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available
from the repositories
I also read that you could use "groupid:artificatid:version_goal" so I tried:
mvn io.swagger:swagger-codegen-maven-plugin:2.4.0-SNAPSHOT:generate
This seems to get further but gives an error
Failed to execute goal
io.swagger:swagger-codegen-maven-plugin:2.4.0-SNAPSHOT:generate
(default-cli) on project com.carus.api.base: The parameters
'inputSpec', 'language' for goal
io.swagger:swagger-codegen-maven-plugin:2.4.0-SNAPSHOT:generate are
missing or invalid
My pom structure is slightly complex. There are several APIs. Each is in some ways their own project. They have a common parent pom with the execution goal in, and the project pom only sets certain variables. The variable used as inputSpec is defined in the project pom, but the one for language in the base pom. (The .base project mentioned here is actually where the base pom is, and is an abstract package (<packaging>pom</packaging>). If I specify a specific project I get the same error but referring to that project.
Questions:
Can I even achieve what I want (generate code from the spec and
compile just that code but not the whole project) with a goal?
How to find out what "prefix" to use for the "prefix:goal" syntax?
The closest I have come is run mvn generate-sources -Dcheckstyle.skip=true. This generates but I don't think it compiles the generated classes. So I then have to clean the project in Eclipse to trigger it to recompile.
How to find out what "prefix" to use for the "prefix:goal" syntax?
The prefix for the plugin should be in this file: "swagger-maven-plugin-2.3.1.jar/META-INF/maven/com.github.kongchen/swagger-maven-plugin/plugin-help.xml".
<plugin>
<name>Swagger Maven Plugin</name>
...
<goalPrefix>swagger</goalPrefix>
...

How do I verify that my eclipse project is effectively using tycho

I am transitioning to Maven-Tycho and was dealing with many errors. I seem to have gotten rid of all the errors but when I look into the pom.xml file I see maven-install-plugin, maven-compiler, maven-release plugin, etc and no mentions of tycho like I see in my tutorial. Did I do something wrong how do I make sure that my project is using maven-tycho not maven only.
http://www.vogella.com/tutorials/EclipseTycho/article.html
Any changes can be made in the pom.xml tab. The Effective POM tab is read-only, it just shows what Maven constructs when it parses your project. It's composed of your POM and its (grand)parent POMs. The Effective POM does not exist on your filesystem per se, it's generated on-the-fly whenever your run a Maven build - hence why the view is "read-only". You can change to tycho-compiler by modifying the pom.xml file replace maven-compiler-plugin with tycho-compiler-plugin. Make sure you add tycho to your eclipse environment

What is the purpose of the # symbol in <groupId>#project.groupId#</groupId>?

I'm trying to run 'mvn clean install' in a sub-module of a multi-module project. The project is Jacoco but I assume it's more an issue of me not understanding how Maven is being used here than an issue with Jacoco itself.
https://github.com/jacoco/jacoco/blob/master/jacoco-maven-plugin.test/it/it-site/pom.xml
I get the following error:
[ERROR] Plugin #project.groupId#:jacoco-maven-plugin:#project.version#
or one of its dependencies could not be resolved: Failed to read
artifact descriptor for
#project.groupId#:jacoco-maven-plugin:jar:#project.version#
I see the following in the pom:
<groupId>#project.groupId#</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
I'm not familiar with using the # symbol in #project.groupId# although i assume it is somehow supposed to get substituted at runtime.
I can run Maven from the top level pom and I even see [INFO] Building: it-site/pom.xml in the log but a target directory is not created there.
A nudge in the right direction would be appreciated.
This probably has something to do with the pom file here: https://github.com/jacoco/jacoco/blob/master/jacoco-maven-plugin.test/pom.xml
It is using a plugin called the maven invoker.
The Invoker Plugin is used to run a set of Maven projects. The plugin can determine whether each project execution is successful, and optionally can verify the output generated from a given project execution.
And if you read about filtering files with this plugin, it mentions:
POM files selected by the include/exclude patterns. The tokens to be filtered must be enclosed in #...# to avoid interferences with Maven's normal POM interpolation, i.e. use #project.version# instead of ${project.version}.
Regarding why the Invoker Plugin and filtering is being used here...
The Spring Boot documentation provides some relevant background on why that is. Although the docs are for Spring Boot, i think it applies to testing all plugins (which Jacoco is).
Multi-module Maven builds cannot directly include maven plugins that
are part of the reactor unless they have previously been built. ...
The standard build works around this restriction by launching the
samples via the maven-invoker-plugin so that they are not part of the
reactor.
The sample application are used as integration tests during the build
(when you mvn install). Due to the fact that they make use of the
spring-boot-maven-plugin they cannot be called directly, and so
instead are launched via the maven-invoker-plugin.

How to add files to a maven project executing generate goal (mvn archetype:generate)?

I'm building a maven archetype project. As parameter (serviceDescriptor), I'm passing path to an xml file. When the generate goal is successfully executed, I would like to have the serviceDescriptor file in src/main/resources. Based on maven archetype documentation, it seems that is not possible but, there should be a way to do it.
I have spent couple of days on this and I think that I have found a reasonable solution.
As I mention in the question, I'm passing the file path as required property to the archetype:generate.
I had to implement a simple plug-in that is executed after archetype generate is finishing. This plug-in is coping the file into src/main/resources, read some data from the file and update the pom.xml setting some properties. In order to be able to modify the pom.xml file I'm using maven-model-2.0 archetype as dependency in maven plug-in. It offers Maven MvenXpp3Reader and MavenXpp3Writer classes that allows to safe modify pom.xml.
In order to tell to archetype project to execute plug-in at the end of generate phase of archetype:
mvn archetype:generate -goals=plugin_groupId:plugin_artifactId:goal
The downside is that the plug-in should be available in a accessible repository or local repo.

Resources