Maven ear problem - maven

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.

Related

How to make Quarkus use local library classes

I'm starting with Quarkus using Maven and can't seem to find a solution to this:
I have a Quarkus app with dependencies on the libraries A and B. Both are imported as "Modules" (not Maven modules!) in the IntelliJ IDEA project for my app.
When starting Quarkus in dev mode, it ignores the classes in target/ of A and B and instead loads them from the Maven repository. Therefore with every change in either A or B, I have to mvn install the respective library, so my Quarkus app uses the correct code.
Coming from Thorntail, this was not necessary. Is there a solution that doesn't require auto-installing A and B on every build and also makes HotSwap work for those libs?
Edit:
As #CrazyCoder requested, here's a minimal example of my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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.example</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<quarkus-plugin.version>1.8.3.Final</quarkus-plugin.version>
<quarkus.platform.version>1.8.3.Final</quarkus.platform.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-universe-bom</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>A</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>B</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
A and B are listed in IntelliJ IDEA under "Project Structure... > Modules > test > Dependencies" as Module Depenencies, not Maven Dependencies. So the code in A and B should be HotSwappable.
I eventually found the solution. As so often: Once you know it, it's trivial.
Open your run configuration, expand the Environment dropdown (only populated when an application module is selected) and check the option Resolve Workspace artifacts:

Transitive maven plugin dependency configuration

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.

Flexmojos-maven-plugin - How to configure multiple source mxml files to generate multiple swf files?

Current working code:
I am able to build a flex project using flexmojos-maven-plugin successfully. However, I can only provide one 'sourceFile' under my plugin configuration. Refer below my working pom.xml, which builds Main.mxml file correctly from 'src' directory. It generates the 'swf' file for Main.mxml successfully:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>com.test</groupId>
<artifactId>TA_UI_Test2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>swf</packaging>
<name>TA_UI_Test2 Flex</name>
<dependencies>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>playerglobal</artifactId>
<version>10-3.3.0.4852</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>rpc</artifactId>
<version>4.5.1.21328</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>framework</artifactId>
<version>3.2.0.3958</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>mx</artifactId>
<version>4.5.0.19786</version>
<type>pom</type>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.8</version>
<extensions>true</extensions>
<configuration>
<sourceFile>Main.mxml</sourceFile>
<debug>true</debug>
<storepass/>
</configuration>
<dependencies>
<dependency>
<groupId>com.adobe.flex</groupId>
<artifactId>compiler</artifactId>
<version>3.2.0.3958</version>
<type>pom</type>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Problem description:
Now I have got multiple other mxml files under my 'src' directory, i.e. all mxml files under one single 'src' directory. How do I add them in above plugin, which only expects one single name in sourceFile configuration?
Things I have tried:
I tried copy-pasting multiple blocks of flexmojos-maven-plugin, and each of them having different sourceFile specified. However, that does not help, because maven just generates the final 'swf' file from the last block of flexmojos-maven-plugin. For eg. if first plugin block has sourceFile Main.mxml, and second plugin block has sourceFile Secondary.mxml, then the 'swf' will be generated for Secondary.mxml only, not for Main.mxml.
Could you provide any other suggestions to generate individual swf files for respective mxml files using single pom/maven build?
After quite a lot of R&D, trying a few hacks, and based on valuable suggestion of Christofer Dutz on this forum, finally a clean solution is available for above problem. Here is the updated pom.xml, which will generate the individual swf files for provided source files:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>com.test</groupId>
<artifactId>TA_UI_Test2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>swf</packaging>
<name>TA_UI_Test2 Flex</name>
<dependencies>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>playerglobal</artifactId>
<version>10-3.3.0.4852</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>rpc</artifactId>
<version>4.5.1.21328</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>framework</artifactId>
<version>3.2.0.3958</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>mx</artifactId>
<version>4.5.0.19786</version>
<type>pom</type>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.8</version>
<extensions>true</extensions>
<configuration>
<storepass></storepass>
</configuration>
<executions>
<execution>
<id>default-compile-swf</id> <!--DO NOT change this ID, else the plugin execution will fail.-->
<configuration>
<sourceFile>File1.mxml</sourceFile>
<debug>true</debug>
<output>${basedir}/target/File1.swf</output>
</configuration>
<goals>
<goal>compile-swf</goal>
</goals>
</execution>
<execution>
<id>default-compile-swf-2</id>
<configuration>
<sourceFile>File2.mxml</sourceFile>
<debug>true</debug>
<output>${basedir}/target/File2.swf</output>
</configuration>
<goals>
<goal>compile-swf</goal>
</goals>
</execution>
<execution>
<id>default-compile-swf-3</id>
<configuration>
<sourceFile>File3.mxml</sourceFile>
<debug>true</debug>
<output>${basedir}/target/File3.swf</output>
</configuration>
<goals>
<goal>compile-swf</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.adobe.flex</groupId>
<artifactId>compiler</artifactId>
<version>3.2.0.3958</version>
<type>pom</type>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Important note: You have to provide the ID of any one of the executions as 'default-compile-swf', without which it would fail to identify the source file. For more information on the error which it will throw, refer to the link of the forum given above where I was discussing the same.
Hope this helps someone someday :)

Building EAR with multiple wars by accessing repositories remotly

I am trying to create ear with multiple wars. Let's say i have 3 web projects with the name web1, web2, web3. These 3 web projects repositories are placed in SVN. So now i wants to create a pom.xml file which creates ear with 3 wars by accessing 3 repositories in one ear file.
I tried it by placing all modules locally using below configuration.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<defaultJavaBundleDir>lib</defaultJavaBundleDir>
<skinnyWars>true</skinnyWars>
<archive>
<manifestEntries>
<Implementation-Description>${project.description}</Implementation-Description>
<Implementation-Vendor>Demo</Implementation-Vendor>
<Implementation-Version>${project.version}</Implementation-Version>
</manifestEntries>
</archive>
<modules>
<webModule>
<groupId>com.demo.ps</groupId>
<artifactId>web1</artifactId>
<bundleFileName>web1.war</bundleFileName>
<contextRoot>/web1</contextRoot>
</webModule>
<webModule>
<groupId>com.demo.ps</groupId>
<artifactId>web1</artifactId>
<bundleFileName>web2.war</bundleFileName>
<contextRoot>/web2</contextRoot>
</webModule>
</modules>
<defaultLibBundleDir>lib</defaultLibBundleDir>
</configuration>
</plugin>
and under dependencies
<dependency>
<groupId>com.demo.ps</groupId>
<artifactId>web1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.demo.ps</groupId>
<artifactId>web1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.demo.ps</groupId>
<artifactId>web2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.demo.ps</groupId>
<artifactId>web2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>pom</type>
</dependency>
by using above configuration it is creating 2 individual wars inside ear file, but i want some guidance to build same by accessing both repositories remotely.
Thanks in advance !!!!

Error: 'dependencies.dependency.version' must be a valid version but is

I have this parent POM file (hawaii-banner\pom.xml):
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>base</artifactId>
<groupId>org.sakaiproject</groupId>
<version>2.9.3</version>
<relativePath>../pom.xml</relativePath>
</parent>
<name>University of Hawaii Banner</name>
<groupId>edu.hawaii.sakai</groupId>
<artifactId>hawaii-banner</artifactId>
<version>${hawaii.banner.version}</version>
<packaging>pom</packaging>
<properties>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<hawaii.banner.version>2.5.0</hawaii.banner.version>
<uh-gatech.version>2.5.1</uh-gatech.version>
</properties>
<dependencies>
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>sakai-kernel-api</artifactId>
<version>${sakai.kernel.version}</version>
</dependency>
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>sakai-kernel-util</artifactId>
<version>${sakai.kernel.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
<!-- Exclude by default the tests that use remote systems. -->
<excludes>
<exclude>**/*Test.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module>api</module>
<module>impl</module>
<module>integration-test</module>
<module>pack</module>
<module>sections-impl</module>
</modules>
</project>
And this child POM file (hawaii-banner\api\pom.xml):
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>edu.hawaii.sakai</groupId>
<artifactId>hawaii-banner</artifactId>
<version>2.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<name>University of Hawaii Banner API</name>
<groupId>edu.hawaii.sakai</groupId>
<artifactId>hawaii-banner-api</artifactId>
<version>${hawaii.banner.version}</version>
<packaging>jar</packaging>
<properties>
<deploy.target>shared</deploy.target>
</properties>
<dependencies>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</dependency>
<dependency>
<groupId>edu.gatech.sakai</groupId>
<artifactId>uh-gatech-banner-api</artifactId>
<version>${uh-gatech.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
But I'm getting this error:
[ERROR] 'dependencies.dependency.version' for edu.gatech.sakai:uh-gatech-banner-api:jar must be a valid version but is '${uh-gatech.version}'. # edu.hawaii.sakai:hawaii-banner-api:${hawaii.banner.version}, C:\hawaii-sakai-2.9.3\sakai-src-2.9.3\hawaii-banner\api\pom.xml, line 26, column 16
I don't understand why I'm getting this error because uh-gatech.version is defined in the parent POM file, and <version>${uh-gatech.version}</version> used to be <version>2.5.1</version>, which worked.
I ran mvn clean install from the same directory as the parent POM file, and it didn't work.
If maven gives this error, it means that the child module does not recognize the parent properly. I've seen this happen with wrong versions.
You think you are defining the right parent, but you are not. As #jordan suggested, by eliminating the child-parent relationship, you can see it works.
You cannot define the version of a module to be a variable you defined in the same pom, and maven will not want on this.
Although you think it's 2.5.0, it's not...
I suggest you review this relationship definition in your project.
I hope this helps.

Resources