I have a gradle multimodule project using the maven publish plugin.
The publish task fails as the maven publish plugin generates an invalid POM.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xmlns="http://www.w3.org/2000/xmlns/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xmlns="http://www.w3.org/2000/xmlns/">
<modelVersion xmlns="http://maven.apache.org/POM/4.0.0">4.0.0</modelVersion>
<groupId xmlns="http://maven.apache.org/POM/4.0.0">com.example</groupId>
<artifactId xmlns="http://maven.apache.org/POM/4.0.0">application</artifactId>
<version xmlns="http://maven.apache.org/POM/4.0.0">0.2.0-SNAPSHOT</version>
<packaging xmlns="http://maven.apache.org/POM/4.0.0">pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.1.RELEASE</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
</project xmlns="http://maven.apache.org/POM/4.0.0">
It clearly is invalid as there are duplicated attributes in the project starting element and the closing element has 'xmlns="http://maven.apache.org/POM/4.0.0"'
I tried gradle 5.6.0 and 6.1.1 with the same outcome.
Any idea how to fix this and what could be the cause?
I solved by applying the maven publish plugin at root project level.
When I add the code below to one of the subproject I want to publish, the generated pom is invalid:
plugins {
id 'nebula.release' version '14.0.3'
id 'maven-publish'
id 'nebula.maven-publish' version '14.1.1'
}
Related
I have a maven project which consist of 1 groovy script (src/main/groovy/Main.groovy)
I am able to run it from IntelliJ by simply clicking run. What I want to do is to create an executable jar containing all dependencies so I could run in with
java -jar myjar.jar
Here's my pom:
<?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>groupId</groupId>
<artifactId>artifactId</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
</dependencies>
</project>
I've searched on google and on so but couldn't find any working solution.
Using Maven you can set up build plugins, and one of these can be a Groovy compiler.
I wrote a blog article on setting up a Groovy compiler in Maven. But there's two parts: the groovy compiler and a plugin to package the .class files into the .jar. Traditionally for the former you'd use the groovy-eclipse-compiler and the maven-shade-plugin for the latter.
It's like 100 lines of XML in your pom file.
I created my own maven project (project 1) where I have added dependencies like junit, spring, etc. and deployed the jar (name it as jar1 ) in my nexus maven repository.
Now when I add jar1 as dependency to my new project 2, only jar1 is getting downloaded from the maven repository and the transitive dependencies such as junit ,spring are not downloaded.
pom - project1
<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>Project1</groupId>
<artifactId>Project1</artifactId>
<version>Dev.0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
pom - project2
<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>Project2</groupId>
<artifactId>Project2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>Project1</groupId>
<artifactId>Project1</artifactId>
<version>Dev.0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
As per above pom configuration, project2 should automatically resolve junit jar right?.
But project2 only resolves Project1.jar and not the junit jar. Please let know what am I missing.
Not all scopes are transitive, especially test and provided dependencies are not.
Look at the table in https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
Hi I am new to Maven and JSoup and trying to run an example in Intellij so I can get an understanding of JSoup.
I added the dependencies of JSoup to my POM.xml file. I pushed to Github when the project was working. As soon as I pulled from Github the project won't run. So I went into the terminal and getting JSoup errors that certain imports don't exist. I tried to 'run' as a Maven project but now I'm even more confused.
Please see the image below which demonstrates the file structure. The code is simple its the config / setup that I am really struggling with.
Project Structure
The POM.xml content is seen below:
<?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>WebScraper</groupId>
<artifactId>WebScraper</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<!-- jsoup HTML parser library # http://jsoup.org/ -->
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.10.2</version>
</dependency>
</dependencies>
</project>
Hopefully someone can help with this.
Thanks
I compile spring webflow samples project using maven in mac os and got errors. (The project compiled successfully in windows)
So I create a simple maven project to reproduce the error.
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>test</groupId>
<artifactId>test</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<dependencies>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
src/main/java/Test.java
import javax.servlet.ServletContext;
public class Test {
public void init(ServletContext context) {
context.setInitParameter("javax.faces.DEFAULT_SUFFIX", ".xhtml");
}
}
mvn compile
The error is:
I thought is was something that maven used a wrong servlet-api.jar but not servlet as pom dependency specified which is correct. (I use javac -cp javax.servlet-api-3.0.1.jar Test.java, result no error)
I check mvn dependency:tree, the result show correct servlet-api-3.0.1.jar.
I also chech mvn script to see if there is some option to set classpath.
But I just can't figure out how maven use which jars as it's classpath.
It's very weird.
After I've imported this test maven project into eclipse,
I run mvn compile again, no error happened.
At my workplace, different groups works on providing different services.
My team consumes these services. Currently, whenever a new version of Service is rolled out, we manually change the pom.xml to the latest version of dependency and then make a build. I am wondering if there is an automatic way of pulling latest release into build.
Here is an example to explain:
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">
<groupId>com.company.product</groupId>
<artifactId>User-Application</artifactId>
<version>1.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<Service1-version>1.0.2</Service-1>
<Service2-version>1.1.2</Service-2>
<Service3-version>2.0.2</Service-3>
</properties>
<dependencies>
<dependency>
<groupId>com.company.product</groupId>
<artifactId>Service1</artifactId>
<version>${Service1-version}</version>
</dependency>
<dependency>
<groupId>com.company.product</groupId>
<artifactId>Service2</artifactId>
<version>${Service2-version}</version>
</dependency>
<dependency>
<groupId>com.company.product</groupId>
<artifactId>Service3</artifactId>
<version>${Service3-version}</version>
</dependency>
.....
....
</project>
When new release of each service is made, we manually change the pom.xml to get the latest dependency. How can this be managed automatically?
The versions-maven-plugin should be able to do this with the task versions:update-properties. See an example here.