Transitive maven plugin dependency configuration - maven

If I have two maven plugins, where A depends on B and B has configuration parameters, how and where should I define configuration for B?
I could think of three solutions, which of one I know is not applicable, and I'm not sure which one works, or there are any more possiblities. Unfortunately, I couldn't find any example even for this simple case.
Try 1 (not possible)
Put <configuration> under dependencies. This is not possible as a <dependency> tag cannot contain a <configuration> tag (see xsd).
<plugin>
<groupId>A</groupId>
<artifactId>A</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>B</groupId>
<artifactId>B</artifactId>
<version>1.0.0</version>
<configuration>
<paramForB><param>bbb</param></paramForB>
</configuration>
</dependency>
</dependencies>
</plugin>
Try 2
Put the configuration parameter under the config of A.
<plugin>
<groupId>A</groupId>
<artifactId>A</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>B</groupId>
<artifactId>B</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<configuration>
<paramForB><param>bbb</param></paramForB>
</configuration>
</plugin>
Try 3
Introduce B as a separate plugin with the configuration I need.
<plugin>
<groupId>B</groupId>
<artifactId>B</artifactId>
<version>1.0.0</version>
<configuration>
<paramForB><param>bbb</param></paramForB>
</configuration>
</plugin>
<plugin>
<groupId>A</groupId>
<artifactId>A</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>B</groupId>
<artifactId>B</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</plugin>
Further questions (just curious)
Also, what if B depends on C. How should I configure C?
And if I have a maven plugin X which also depends on B but would use it with other configuration: can I do that?

In maven you have profiles and properties.
First start with properties:
Project B
<properties>
<customeParameter>parameterInB</customeParameter>
</properties>
<plugin>
<groupId>A</groupId>
<artifactId>A</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>B</groupId>
<artifactId>B</artifactId>
<version>1.0.0</version>
<configuration>
<paramForB>${customeParameter}</paramForB>
</configuration>
</dependency>
</dependencies>
</plugin>
Project A
<properties>
<customeParameter>overrideInA</customeParameter>
</properties>
See my answer to question: How to get a command-line property to overwrite a maven property
My example will work if project B is a parent for project A. If not, please define share configuration in parent pom (which will be parent for A and B) and parametrize it. Then in child you can define in "properties" section values for this configuration.

The answer is basically Try 2, i.e., add configurations of B to the plugin usage A, but it depends on how plugin A was implemented as it its responsibility to pass the parameters.

Related

How to add and artifact located at openhab repository with Maven?

I am looking to add a dependency to my pom.xml file
The dependency is a library allowing to manipulate Bluetooth Low Energy devices. Here is the link : TinyB
Here is also the github of the library : intel-iot-devkit/tinyb
When I copy and paste the snippet code to add the dependency, I get the following error after Maven tries to resolve the dependencies :
Could not find artifact intel-iot-devkit:tinyb:pom:0.5.1 in central (https://repo.maven.apache.org/maven2)
Could this be because the artifact is located in the OpenHab repository ? Then if this may cause the problem, how to solve it ?
Here is a copy of my pom.xml file :
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.HAcare</groupId>
<artifactId>HAcare_Connector</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>15.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>15.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/intel-iot-devkit/tinyb -->
<dependency>
<groupId>intel-iot-devkit</groupId>
<artifactId>tinyb</artifactId>
<version>0.5.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.6</version>
<executions>
<execution>
<!-- Default configuration for running -->
<!-- Usage: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>org.HAcare.App</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
And here is the code snippet I added to pom.xml :
<dependency>
<groupId>intel-iot-devkit</groupId>
<artifactId>tinyb</artifactId>
<version>0.5.1</version>
</dependency>
There is a second repository where it is possible to use this library by adding a dependency to the pom.xml file. Indeed it seems that the libraries are stored on the repository of openHAB.
To proceed you must first :
Add a repositories section in the pom.xml file
Here is a snippet code:
<repositories>
<repository>
<id>openHAB</id>
<name>openHabTinyB</name>
<url>https://openhab.jfrog.io/openhab/libs-release/</url>
</repository>
</repositories>
You have to add the following dependency:
Here is a snippet code:
<!-- https://mvnrepository.com/artifact/org.openhab.osgiify/intel-iot-devkit.tinyb -->
<dependency>
<groupId>org.openhab.osgiify</groupId>
<artifactId>intel-iot-devkit.tinyb</artifactId>
<version>0.5.1</version>
</dependency>

Manually creating a deployable JAR for Liferay

I created a liferay workspace in gradle format and it basically only contains a theme and a TemplateContextContributor-module.
Now I want to build a maven "wrapper" around both artifacts to make them compatible with some other maven-processes/-plugins while keeping the original gradle structure. I dont want to use the liferay-maven-plugin or maven-tools to build those artifacts, because it seems to behave differently from the gradle/gulp toolset when it comes to compiling scss for example.
So I created some POMs from scratch for
Theme
TemplateContextContributor-Module
First off I will take about the mechanism for the theme, which is already working:
That wrapper uses the maven-war-plugin to bundle the contents of the build/-folder, where the previously built gradle artifact resides, into a WAR-file that can be deployed by Liferay without problems.
theme pom.xml:
<properties>
<src.dir>src</src.dir>
<com.liferay.portal.tools.theme.builder.outputDir>build</com.liferay.portal.tools.theme.builder.outputDir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
[...]
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<webResources>
<resource>
<directory>${com.liferay.portal.tools.theme.builder.outputDir}</directory>
<excludes>
<exclude>**/*.sass-cache/</exclude>
</excludes>
</resource>
</webResources>
</configuration>
</plugin>
However, I am having difficulties creating a OSGI-Compatible JAR-File for the module contents. It seems that only the META-INF/MANIFEST.MF does not contain the right information and I seemingly cannot generate it in a way that Liferay (or OSGI) understands.
this is the module pom.xml dependencies and plugins that I tried:
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.ds-annotations</artifactId>
<version>1.2.10</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay</groupId>
<artifactId>com.liferay.gradle.plugins</artifactId>
<version>3.9.9</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>com.liferay.portal.kernel</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
[...]
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<goals>
<goal>bnd-process</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bndlib</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>com.liferay</groupId>
<artifactId>com.liferay.ant.bnd</artifactId>
<version>2.0.48</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>1.25.0</version>
<executions>
<execution>
<id>generate-scr-scrdescriptor</id>
<goals>
<goal>scr</goal>
</goals>
</execution>
</executions>
</plugin>
I was able to create a JAR using the above but its' META-INF/MANIFEST.MF is not identical to the one produced by the gradle build:
I guess that's why Liferay does not deploy it. The log says "processing module xxx ....", but that never ends and the module does not work in Liferay.
These are the plugins I have tried in different combinations so far:
maven-build-plugin
maven-scr-plugin
maven-jar-plugin
maven-war-plugin
maven-compiler-plugin
Any help in creating a liferay-deployable module JAR would be great.
I'm not sure why you're manually building a maven wrapper for the Template Context Contributor. The Liferay (blade) samples are available for Liferay-workspace, pure Gradle as well as for Maven. I'd just go with the standard and not worry about re-inventing the wheel.
To make this answer self-contained: The current pom.xml listed in the Template Context Contributor plugin is:
<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>
<artifactId>template-context-contributor</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<parent>
<groupId>blade</groupId>
<artifactId>parent.bnd.bundle.plugin</artifactId>
<version>1.0.0</version>
<relativePath>../../parent.bnd.bundle.plugin</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>com.liferay.portal.kernel</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>com.liferay.blade.template.context.contributor-${project.version}</finalName>
</build>
</project>

maven-schemaspy-plugin doesn't work (maybe it's a repository issue)

I want to generate a er-diagram from a database integrated in the maven lifecycle.
SchemaSpy generates the er-diagram and with the maven-schemaspy-plugin it should be possible to integrate this in the lifecyle-process.
(If anyone has a better idea for this please let me know)
I tried it with the following simple pom.xml (which only should generate the er-diagram); but the plugin doesn't start; it couldn't even be downloaded:
<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.schemaspy</groupId>
<artifactId>SchemaSpyGenerateDB_02</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SchemaSpyGenerateDB_02</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>maven-plugins</groupId>
<artifactId>maven-schemaspy-plugin</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>maven-plugins</groupId>
<artifactId>maven-schemaspy-plugin</artifactId>
<version>1.0</version>
<type>plugin</type>
</dependency>
</dependencies>
<!-- To use the report goals in your POM or parent POM -->
<reporting>
<plugins>
<plugin>
<groupId>maven-plugins</groupId>
<artifactId>maven-schemaspy-plugin</artifactId>
<version>1.1</version>
<configuration>
<databaseType>derby</databaseType>
<database>JPACertifiaction_Relationship</database>
<host>localhost</host>
<port>1527</port>
<user>user</user>
<password>password</password>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
The command
mvn site:site
causes the message
The POM for maven-plugins:maven-schemaspy-plugin:jar:1.0 is missing, no dependency information available
The POM for maven-plugins:maven-schemaspy-plugin:plugin:1.0 is missing, no dependency information available
I've also tried it with the following settings with no success:
<dependency>
<groupId>com.wakaleo.schemaspy</groupId>
<artifactId>maven-schemaspy-plugin</artifactId>
<version>5.0.1</version>
</dependency>
....
<reporting>
<plugins>
<plugin>
<groupId>com.wakaleo.schemaspy</groupId>
<artifactId>maven-schemaspy-plugin</artifactId>
<version>5.0.1</version>
....
<repository>
<id>Wakaleo Repository</id>
<url>http://maven.wakaleo.com/mojo/maven-schemaspy-plugin/</url>
</repository>
What me also confuses is that there are different reposititories with different versions 1.0 / 5.0.1 so what is really the official one ?
You don't need the entries
<dependencies>
<dependency>
<groupId>maven-plugins</groupId>
<artifactId>maven-schemaspy-plugin</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>maven-plugins</groupId>
<artifactId>maven-schemaspy-plugin</artifactId>
<version>1.0</version>
<type>plugin</type>
</dependency>
</dependencies>
delete them. When you define a plugin (plugin section later) it gots downloaded by maven automatically. Your error message says that 1.0 is missing, but your plugin is 1.1, so it doesn'T fit to your dependencies anyway.
The maven-schemaspy-plugin and the com.wakaleo.schemaspy plugin are different plugins from different authors. None of them is the "official schemaspy" maven plugin. I was only able to solve it with the wakaleo plugin (with maven 3). The other plugin seams not to be available any more.
With Maven 3 the site generation changed, see site generation in Maven 3. As mentioned in this blog entry you have to include the plugin in this way (note that the versioning has changed):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.1</version>
<configuration>
<reportPlugins>
<plugin>
<groupId>com.wakaleo.schemaspy</groupId>
<artifactId>maven-schemaspy-plugin</artifactId>
<version>1.0.4</version>
<configuration>
<databaseType>derby</databaseType>
<database>JPACertifiaction_Relationship</database>
<host>localhost</host>
<port>1527</port>
<user>user</user>
<password>password</password>
</configuration>
</plugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
and you need the link to the repository:
<pluginRepositories>
<pluginRepository>
<id>Wakaleo Repository</id>
<url>http://www.wakaleo.com/maven/repos/</url>
</pluginRepository>
</pluginRepositories>
Then the plugin starts. The rest is up to you :-)

Maven ear problem

I'm finishing my project build (with maven), and it's working great. Now I just have to "pack it", as an ear.
All I need to do is pack 3 dependencies, one .jar and 2 .war. Don't ask me how, that was the way it was done before (with ant), and I'm translating it to maven - next I'll organize the packages, so we can be more productive.
However, I'm having a few problems. First, the package is named null-${version}.ear. It copies itself right to the repository, but in the target folder is wrongly named. And second, it's copying all the other packages dependencies. I want to know what can I do about the null name, and the copying of the packages.
Here is my pom:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>owner</groupId>
<artifactId>coreisp</artifactId>
<version>2.0</version>
</parent>
<groupId>owner</groupId>
<artifactId>coreisp-app</artifactId>
<packaging>ear</packaging>
<version>2.0</version>
<name>Projeto CoreISP</name>
<dependencies>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>coreisp-core</artifactId>
<version>${pom.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>coreisp-initializer</artifactId>
<type>war</type>
<version>${pom.version}</version>
</dependency>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>coreisp-site</artifactId>
<type>war</type>
<version>${pom.version}</version>
</dependency>
</dependencies>
<build>
<finalName>${application.id}-${pom.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.3</version>
<configuration>
<modules>
<jarModule>
<groupId>owner</groupId>
<artifactId>coreisp-core</artifactId>
<includeInApplicationXml>
true
</includeInApplicationXml>
<bundleDir>/</bundleDir>
</jarModule>
<webModule>
<groupId>owner</groupId>
<artifactId>
coreisp-initializer
</artifactId>
<bundleDir>/</bundleDir>
</webModule>
<webModule>
<groupId>owner</groupId>
<artifactId>
coreisp-site
</artifactId>
<bundleDir>/</bundleDir>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
</project>
First of all remove the element from your POM, the application.id property is what gives you the "null" name.
As to ensure that transitive dependencies do not end up in your EAR I suggest you specify explicitly in your POM what you do want and what you do not want. In order to keep a dependency out all you need to do is define it in your POM with a scope of provided. I know it's a painful job, but in my opinion it's worth it, to ensure that you get exactly what you want.

How to set -Euwc param with axis2-wsdl2code-maven-plugin?

We are using axis2 to generate web-service clients, (I regret this now!). With axis2 command-line tool you can pass switch -Euwc to wrap int into Integer, boolean into Boolean and so on in generated soruces. This is the one way to tell axis2 that its OK for certain int or boolean values to be nillable in schema.
My question is how do you set this parameter via POM or other means with Maven to achieve same behaviour with genrated sources? My stackoverflow and google searches aren't revealing much. There's a Jira issue, which seems to be closed by developers without pointing in right direction.
<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>com.futile.bizzareservice</groupId>
<artifactId>BizzareService</artifactId>
<version>2.0</version>
<name>BizzareService</name>
<properties>
<wsdl.location>unfortunate-wsdls</wsdl.location>
<axis2.version>1.5.4</axis2.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>${axis2.version}</version>
<configuration>
<packageName>com.futile.bizzareservice.client</packageName>
<wsdlFile>${wsdl.location}/bizzareservice.wsdl</wsdlFile>
<language>java</language>
<databindingName>adb</databindingName>
<unpackClasses>true</unpackClasses>
</configuration>
<executions>
<execution>
<goals>
<goal>wsdl2code</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb-codegen</artifactId>
<version>${axis2.version}</version>
</dependency>
</dependencies>
</project>
Setting unwrap to true in configuration doesn't help, as it's a different option all together. I will look to avoid axis2 in the future but for time being we're stuck with it.
After long meditation with sources I found solution: insert
<options>
<uwc>true</uwc>
</options>
in configuration section.
Use
<options>
<osv>true</osv>
<iu>true</iu>
</options>
This only works with 1.7.2 version of Axis

Resources