Maven ignoring variables in child pom - java

i been stuck with this for a while.
I am trying to automate the build and deploy (in nexus3) of several java modules and remove the need for manually set the module version in the projects pom.
My issue is that maven is ignoring the variables inside the pom files.
Parent pom:
<properties>
<revision>local</revision>
</properties>
<name>lib-cloud</name>
<groupId>com.company.lib</groupId>
<artifactId>lib-cloud</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<modules>
<module>lib-cloud-main</module>
</modules>
and the child pom:
<properties>
<unrelatedVAR>2017.3.3</unrelatedVAR>
</properties>
<parent>
<groupId>com.company.lib</groupId>
<artifactId>lib-cloud</artifactId>
<version>${revision}</version>
</parent>
<artifactId>lib-cloud-main</artifactId>
<name>lib-cloud-main</name>
and then i build this with:
mvn -Drevision=3.1 clean package deploy
This build the code just fine, create a lib-cloud-main/target/lib-cloud-main-3.1.jar
In side the jar, i can already see that
lib-cloud-main-3.1.jar/maven/com.company.lib/lib-cloud-main/pom.xml have
<version>${revision}</version>
As version, instead 3.1 as i would expected, but still this artifact manages to be saved in nexus.
If i try to use it, however, maven trow the error when trying to get the pom:
[ERROR] Failed to execute goal on project core-backend-api: Could not resolve dependencies for project com.company.core:core-backend-api:jar:local: Failed to collect dependencies at com.company.lib:lib-cloud-main:jar:3.1: Failed to read artifact descriptor for com.company.lib:lib-cloud-main:jar:3.1: Could not transfer artifact com.company.lib:lib-cloud:pom:${revision} from/to company-maven-public (http://mvn.company.local/repository/maven-public/): Failed to transfer file: http://mvn.company.local/repository/maven-public/com/company/lib/lib-cloud/$%7Brevision%7D/lib-cloud-$%7Brevision%7D.pom. Return code is: 400 , ReasonPhrase:Invalid repository path.
I even tried to use
mvn release:update-versions -DdevelopmentVersion=3.1
As a way to overwrite the poms with a static value before the build but this methos STILL fail to touch the tag in any project children pom.
What i am doing wrong?
Apache Maven 3.5.4 (Red Hat 3.5.4-4) Maven home: /usr/share/maven Java
version: 1.8.0_212, vendor: Oracle Corporation, runtime:
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.fc29.x86_64/jre
Default locale: pt_BR, platform encoding: UTF-8 OS name: "linux",
version: "5.0.17-200.fc29.x86_64", arch: "amd64", family: "unix"

You should use release plugin to do this.
mvn release:update-versions -DautoVersionSubmodules=true

Related

How can I download Infrequently used dependencies in maven?

Version: maven 3.6.3
I try to put this dependency into pom.xml,but it not auto download
<dependency>
<groupId>com.datastax.spark</groupId>
<artifactId>spark-cassandra-connector_2.11</artifactId>
<version>2.4.3</version>
</dependency>
so i use command line:
mvn dependency:get -DremoteRepositories=http://repo1.maven.org/maven2 -DgroupId=com.datastax.spark -DartifactId=spark-cassandra-connector_2.11 -Dversion=2.4.3 -Dtransitive=false
but it give me couldn't download artifact error log :
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.8:get (default-cli) on project standalone-pom: Couldn't download artifact: Could not transfer artifact com.datastax.spark:spark-cassandra-connector_2.11:jar:2.4.3
Do I need to upgrade remoteRepositories?
Why are some commonly used packages automatically downloaded quickly ? such as guava,commons-lang.
Some new versions are always problematic to rely on for download,Is it no cache in
repository?
How can I download the dependency? Thanks

Could not transfer artifact (https://repo.maven.apache.org/maven2): Received fatal alert: protocol_version -> [Help 1]

I am new to Maven and trying to setup my first project in Maven but receiving the below error message when I am doing " Run as -> Maven install " in Eclipse. Below is my settings.xml and pom.xml
Settings.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>C:\Users\Iam\.m2\repository</localRepository>
<profiles>
<profile>
<repositories>
<repository>
<id>central</id>
<url>http://central.maven.org/maven2/</url>
</repository>
</repositories>
<pluginRepositories>
</pluginRepositories>
</profile>
</profiles>
</settings>
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.mytest</groupId>
<artifactId>MySpringBootMaven</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.11.RELEASE</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.5</version><!--$NO-MVN-MAN-VER$-->
<configuration>
<warnName>Test.war</warnName>
</configuration>
</plugin>
</plugins>
</build>
</project>
Error message:
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.eclipse.aether.resolution.ArtifactDescriptorException: Failed to read artifact descriptor for org.springframework.boot:spring-boot-maven-plugin:jar:1.5.11.RELEASE
at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:302)
at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(DefaultArtifactDescriptorReader.java:218)
at org.eclipse.aether.internal.impl.DefaultRepositorySystem.readArtifactDescriptor(DefaultRepositorySystem.java:287)
at org.apache.maven.plugin.internal.DefaultPluginDependenciesResolver.resolve(DefaultPluginDependenciesResolver.java:103)
... 27 more
Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: Could not transfer artifact org.springframework.boot:spring-boot-maven-plugin:pom:1.5.11.RELEASE from/to central (https://repo.maven.apache.org/maven2): Received fatal alert: protocol_version
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:444)
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:246)
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:223)
at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:287)
... 30 more
Caused by: org.eclipse.aether.transfer.ArtifactTransferException: Could not transfer artifact org.springframework.boot:spring-boot-maven-plugin:pom:1.5.11.RELEASE from/to central (https://repo.maven.apache.org/maven2): Received fatal alert: protocol_version
How to resolve the Received fatal alert: protocol_version ? My java version is 1.7 and maven version is 3.3.3
Sonatype no longer supports TLSv1.1 and below (effective, June 18th, 2018). My guess is that you are using TLSv1.1 protocol or below.
The documentation I listed gives you 4 options:
Upgrade your Java runtime, for example with OpenJDK builds or Oracle paying support
Configure your Java runtime to enable TLS 1.2 by adding -Dhttps.protocols=TLSv1.2
Use a repository manager that uses a Java version supporting TLS 1.2
Revert back to http until you can acheive one of the above remediation steps.
I fixed it myself by just using -Dhttps.protocols=TLSv1.2 as a VM argument.
 
For a permanent solution(mostly required in Java 7) - in you build directory(where you do the mvn command from) add directory:
.mvn (in cmd mkdir .mvn)
and in it create file
jvm.config
and in put the following line:
-Dhttps.protocols=TLSv1.2
The simplest solution is to configure your JVM runtime arguments. On eclipse, you can do it as following :
go to windows>preferences>java>installed JREs
click on the Intalled JRE/JDK you are using for your project
click on "edit" on le right,
and add -Dhttps.protocols=TLSv1.2 in the Default VM arguments Input field.
see the screenshot :
The Package you are trying to install doesn't support TLS1.1 and you might be by default using TLS 1.1. Configure your Java runtime to enable TLS 1.2 by adding -Dhttps.protocols=TLSv1.2 to your Maven Build command would solve the problem.
For Example: mvn clean install -Dhttps.protocols=TLSv1.2
I had upgraded from Java 1.7 to Java 1.8 and got the same error.
To resolve this error, I checked the mvn version using mvn -version and found that JAVA_HOME was still using the Java 1.7. I changed the JAVA_HOME in the environment variable to point to Java 1.8 jre in JDK
Hope this helps someone.
I set my settings.xml file in the .m2 directory just as the one here: https://github.com/alipay/sofa-rpc/pull/190/files
Then exec mvn install and all dependencies started to download. I haven't had a settings.xml file before and I am not using any proxy.
Hope it helps somebody.
PD. I have jdk 1.7 and Maven 3.3.9
I resolved this error in SpringToolSuit by adding settings.xml file in .m2 folder which is located in Users folder of C drive and by updating Project by
right click on pom.xml -> Maeven -> Update Project.
Make sure you select Force update of snapshots/releases.
It needs both : Configuring the JVM runtime arguments as well as having a settings.xml, after I did both it worked. Updating only the JVM runtime argument did not help.
In my case the automatic update of maven dependencies were disabled in eclipse.
Solution:
Go to
Windows->Preferences->Maven
and uncheck the check box
"Do not automatically update dependencies from remote repositories"
Then update the project
Right click on project->maven->update project
I had the same issue, I tried most of the answers here but still did not work. My issue was Proxy settings on my IDE. So it is also important to remember to check proxy settings. File > Settings > System Settings > HTTP Proxy - Select Auto-Detect proxy settings
On my new laptop (Win10) I have downgraded maven 3.8.7->3.6.3 and jdk 19->1.8
Maven 3.8.7 is blocking a lot of old repositories, one sometimes does need.

Dependency error in eclipse project making use of Maven

I am using Eclipse Mars to run my Java project. I am making use of Maven in it. But while trying to compile my package I am getting the following error.
Failed to execute goal on project apex-check: Could not resolve dependencies for project org.fundacionjala.enforce.sonarqube:apex-check:jar:1.0: Failed to collect dependencies at org.fundacionjala.enforce.sonarqube:apex-squid:jar:1.0: Failed to read artifact descriptor for org.fundacionjala.enforce.sonarqube:apex-squid:jar:1.0: Could not transfer artifact org.fundacionjala.enforce.sonarqube:apex-squid:pom:1.0 from/to central (https://repo.maven.apache.org/maven2): Failed to authenticate with proxy -> [Help 1].
I am able to find that my pom.xml has a bug in its dependency. But don't know how to resolve it. I have given below my pom.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!-- ~ Copyright (c) Fundacion Jala. All rights reserved. ~ Licensed under the MIT license. See LICENSE file in the project root for full license information. -->
<project 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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.fundacionjala.enforce.sonarqube</groupId>
<artifactId>apex</artifactId>
<version>1.0b${build.number}</version>
</parent>
<artifactId>apex-check</artifactId>
<name>Apex :: Checks</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apex-squid</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
I have written 'apex-check' and 'apex-squid' as two separate projects.
Can anyone explain how to correct my pom.xml?
You need to have:
org.fundacionjala.enforce.sonarqube:apex-check:jar:1.0
org.fundacionjala.enforce.sonarqube:apex-squid:jar:1.0
jar files available in your local .m2/repository folder. If they are not present maven will try to download from central repository and as an expected result it will fail on firewall or it will not find the artifact. i.e. if:
apex-check requires apex-squid project as dependency first you need to install squid project files by using mvn install on squid project folder.
But it seems more like you want to create a multi module maven project, take a look at this question. Create a parent project similar to this project, add check and squid as module and run mvn clean install on parent.
**edit: I just see you already have parent, so make sure parent has your projects as modules, which helps reactive build order and eclipse imports

Jersey 2.0 "Getting Started" guide, mainClass not found

Hi I am trying to follow the Getting Started guide for Jersey 2.0.
I did steps 1.1 and 1.2 as is. No problem there.
For step 1.3 I had a problem cause maven could not find the javax-annotation 1.2 but I solved it following the advice of another Stackoverflow user and added a repository to my pom.
Somvn clean test passes with no problems, BUT when I try to run mvn clean exec:java I get back
[WARNING] java.lang.ClassNotFoundException: com.example.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:285)
at java.lang.Thread.run(Thread.java:722)
The pom.xml is the one created by the following command:
mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-grizzly2 \
-DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false \
-DgroupId=com.example -DartifactId=simple-service -Dpackage=com.example \
-DarchetypeVersion=2.0
where the only addition I 've made is the following:
<repositories>
<repository>
<id>java.net.repo</id>
<url>https://maven.java.net/content/groups/promoted/</url>
<layout>default</layout>
</repository>
</repositories>
In case it is of interest this is the output of mvn -version
Apache Maven 3.0.4 (r1232337; 2012-01-17 10:44:56+0200)
Maven home: /usr/share/maven
Java version: 1.7.0_21, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home/jre
Default locale: el_GR, platform encoding: UTF-8
OS name: "mac os x", version: "10.8.3", arch: "x86_64", family: "mac"
I am able to reproduce your error. This has nothing to do with Jersey; it's an error you're making with Maven. mvn clean exec:java says: "delete all the .class files and then try to run the Main .class file". Since you deleted it, Maven can't find it. Here's a solution:
mvn clean compile exec:java
This should fix the problem in your question. This says "delete all the .class files, recompile them from source and then try to run the Main .class file"
To get past the next error you'll see, delete the <scope>test</scope> line from the client dependency in the pom.xml:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<scope>test</scope>
</dependency>
To:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
</dependency>

Maven plugin builds but can't execute due to java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

I am using the maven-jspc-plugin in my pom.xml.
When i try to execute the jsp-compile goal (which executes the plugin) I get:
Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.apache.juli.logging.Slf4jLog.<init>(Slf4jLog.java:29)
at org.apache.juli.logging.LogFactory.getLog(LogFactory.java:54)
at org.apache.juli.logging.LogFactory.getLog(LogFactory.java:35)
at org.apache.sling.scripting.jsp.jasper.compiler.OriginalTldLocationsCache.<init>(OriginalTldLocationsCache.java:81)
at org.apache.sling.maven.jspc.JspcMojo.initServletContext(JspcMojo.java:426)
I've tried downloading the (open) source for the maven-jspc-plugin and i am able to easily "mvn install" -- I don't get any build issues, however when i use that build in my project pom it still crashes and tells me it can't find LoggerFactory.
I've logged an issue with the Apache Sling project but am not making much headway.
https://issues.apache.org/jira/browse/SLING-2350
This link includes some more troubleshooting info as well as a simple maven project that uses the maven plugin. downloading the jspc-test.zip and "mvn install"ing will result in the error I've mentioned.
Also, i took a peak at the org.apache.juli pom.xml and it doesnt appear to list any dependencies at all.
Any thoughts on how to resolve would be appreciated.
Thanks!
Plugin dependencies are supplied in a different part of the POM:
<project>
<dependencies>
<!-- dependencies defined here don't get included for plugins -->
...
</dependencies>
<build>
<plugins>
<plugin>
.... jspc plugin section ....
<dependencies>
<dependency>
<!-- Try adding slf4j here --->
Though it does sounds like their POM is invalid if it doesn't already specify slf4j.

Categories