Invalid packaging error when using Spring Boot's starter web parent - spring

I'd like to use the spring-boot-starter-web parent for my project. Unfortunately if I try to use it I get the following error message:
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Invalid packaging for parent POM org.springframework.boot:spring-boot-starter-web:2.0.5.RELEASE, must be "pom" but is "jar" # org.springframework.boot:spring-boot-starter-web:2.0.5.RELEASE
#
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project com.company:my-artifact:1.0-SNAPSHOT (/home/user/Projects/my-artifact/pom.xml) has 1 error
[ERROR] Invalid packaging for parent POM org.springframework.boot:spring-boot-starter-web:2.0.5.RELEASE, must be "pom" but is "jar" # org.springframework.boot:spring-boot-starter-web:2.0.5.RELEASE
If I change the parent to be spring-boot-starter-parent this error does not happen and the build completes without error.
This is a MWE 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>my-artifact</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.5.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.version>1.2.71</kotlin.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<configuration>
<jvmTarget>1.8</jvmTarget>
</configuration>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The project is a Kotlin project created with IntelliJ by creating a new Maven project from archetype and choosing the kotlin for JVM archetype so the only files I have are pom.xml and the src/main/kotlin/com/company/Hello.kt with the following contents:
package com.company
fun main(args: Array<String>) {
println("Hello, World")
}
And the test file under src/test/kotlin/com/company/HelloTest.kt:
package com.copmany
import org.junit.Test
import kotlin.test.assertEquals
class HelloTest {
}
As far as I can tell my POM is correct. I tried to mvn clean build multiple times but it does not seem to be a problem with the downloaded dependencies. Isn't the spring-boot-starter-web supposed to be used as a parent?

You have to set spring-boot-starter-parent as parent
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>
and spring-boot-starter-web as your dependency
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>

I would recommend using "Spring Boot Reference Guide" from https://docs.spring.io

Related

Managing Maven plugin versions with Spring Boot BOM

I have a Maven POM for a Spring Boot project. The POM imports the Spring Boot BOM. Now I want to customize the configuration of a Maven plugin, say, mvn-compiler-plugin. I'd like to use the plugin version maven-compiler-plugin.version dictated by the spring-boot-dependencies BOM.
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ch.ge.mygroup</groupId>
<artifactId>myartifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<spring-boot.version>2.4.2</spring-boot.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- Spring Boot BOM -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<!-- some particular config here -->
</configuration>
</plugin>
</plugins>
</build>
</project>
But this does work: I come up with a Maven error:
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin must be a valid version but is '${maven-compiler-plugin.version}'. # line 31, column 26
So I have to explicitly specify the version of the Maven plugin, which I want to avoid.
In summary:
Using
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<!-- some particular config here -->
</configuration>
</plugin>
yields a Maven error.
Using
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<!-- some particular config here -->
</configuration>
</plugin>
works, but prevents me from using the version (3.8.1) dictated by the Spring Boot BOM.
Using
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!-- some particular config here -->
</configuration>
</plugin>
works, but uses an old version (3.1) of the plugin.
How can I avoid to explicitly specify the plugin version and instead implicitly use the plugin version provided in the Spring Boot BOM?
If you want to override Spring Boot dependencies by simply updating properties, you have to specify the parent POM instead of importing:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ch.ge.mygroup</groupId>
<artifactId>myartifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.4.2</version>
<relativePath/>
</parent>
<properties>
<spring-boot.version>2.4.2</spring-boot.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<!-- some particular config here -->
</configuration>
</plugin>
</plugins>
</build>
</project>

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:

No schemas have been found - Spring Boot WS

I have the next throuble:
When I follow the Spring boot WS example with maven, when I follow the steps, after add the xsd file, the guide indicate how to add the plugin to pom.xml file and this automatically turn the xsd file into java class objects. But I've received this:
No schemas have been found (org.codehaus.mojo:jaxb2-maven-plugin:1.6:xjc:xjc:generate-sources)
org.apache.maven.plugin.MojoExecutionException: No schemas have been found
at org.codehaus.mojo.jaxb2.AbstractXjcMojo.execute(AbstractXjcMojo.java:376)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:331)
at org.eclipse.m2e.core.internal.embedder.MavenImpl$11.call(MavenImpl.java:1362)
...
Here is my pom.xml:
<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.tester</groupId>
<artifactId>test-ws</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<name>test-ws</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.7</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>${project.basedir}/src/main/resources/</schemaDirectory>
<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
<clearOutputDir>false</clearOutputDir>
</configuration>
</plugin>
</plugins>
</build>
This is a screenshot how is look like the error:
Any help is appreciated!
Ok, if someone has the same error, I got the solution like this:
First, I configured the maven user settings in eclipse by adding a separate repository folder for the related project (Override the default path located in X:\Users\User.m2\repository).
I removed two custom profiles that I had in the previous file.
I updated the project and magically, the error disappeared.
Thanks to all for the help.

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.

Maven Jboss plugin configuration for a multi-module project having a child module as WAR

I am working on a maven multi-module project having the following folder structure.
+---parent_module
+---module1
+---module2
+---module_web
How do I configure 'jboss-as-maven-plugin' for a local and remote deploy? Note that I want to deploy the child module_web which is the WAR residing inside the parent_module. I ran command 'mvn clean install' and the build completed successfully and the module_web.war file was created.
Then I ran the mvn command 'mvn -e -X package jboss-as:deploy' from parent_module to deploy the WAR to the jboss container, I get the following error.
[INFO]
------------------------------------------------------------------------ [ERROR] Failed to execute goal
org.jboss.as.plugins:jboss-as-maven-plugin:7.4.Final:deploy
(default-cli) on project markodojo: Could not execute goal deploy on
C:\Mahesh\Git\markodojo\markodojo\target\markodojo_solution-1.0-SNAPSHOT.war.
Reason: I/O Error could not execute operation '{ [ERROR] "address" =>
[], [ERROR] "operation" => "read-attribute", [ERROR] "name" =>
"launch-type" [ERROR] }': java.net.ConnectException: JBAS012144: Could
not connect to remote://localhost:8080. The connection timed out
[ERROR] -> [Help 1]
Below are the snippets from the pom.xml files.
Parent module pom.xml
<groupId>com.abc</groupId>
<artifactId>abc</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>module1</module>
<module>module2</module>
<module>module_web</module>
</modules>
<properties>
.....
</properties>
<dependencyManagement>
.....
</dependencyManagement>
<build>
<directory>${project.basedir}/target</directory>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<!-- Java EE 6 doesn't require web.xml, Maven needs to catch up! -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!-- JBoss AS plugin to deploy war -->
<!-- To use, run: mvn package jboss-as:deploy -->
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.4.Final</version>
<!-- inherited>true</inherited-->
<configuration>
<jbossHome>C:\folderpath\jboss-as-7.1.1.Final</jbossHome>
<serverName>standalone</serverName>
<hostname>localhost</hostname>
<port>8080</port>
<filename>module_web-1.0-SNAPSHOT.war</filename>
</configuration>
</plugin>
other plugins...
<plugins>
</build>
module1 pom.xml
<parent>
<groupId>com.abc</groupId>
<artifactId>abc</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>module1</artifactId>
<packaging>jar</packaging>
<name>module1</name>
module2 pom.xml
<parent>
<groupId>com.abc</groupId>
<artifactId>abc</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>module2</artifactId>
<packaging>jar</packaging>
<name>module2</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>module1</artifactId>
<version>${project.version}</version>
</dependency>
other dependencies ...
</dependencies>
module_web pom.xml
<parent>
<groupId>com.abc</groupId>
<artifactId>abc</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>module_web</artifactId>
<packaging>war</packaging>
<name>module_web</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>module1</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>module2</artifactId>
<version>${project.version}</version>
</dependency>
other dependencies ...
</dependencies>
Can anyone please let me know what am I doing wrong with the plugin configuration? It would be of great help if you share any tutorial or maven-jboss document which explains the steps to configure the maven-jboss plugin for a multi-module project having a child module as WAR.
Thanks.

Resources