Dependency error in eclipse project making use of Maven - java

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

Related

Maven inside docker container ignoring local repository

I have a maven project with a few custom dependencies that reside on a private repository. I'm attempting to create a docker image based on one of the maven images with these dependencies pre-loaded into the local maven repository.
Dockerfile
FROM maven:3.8.6-openjdk-11-slim
COPY settings-docker.xml /usr/share/maven/ref/
COPY bom.xml /tmp
RUN mvn -B -f /tmp/bom.xml -s /usr/share/maven/ref/settings-docker.xml dependency:resolve
settings-docker.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>/usr/share/maven/ref/repository</localRepository>
<mirrors>
<mirror>
<id>Mirror of Private Repo</id>
<mirrorOf>Private Repo</mirrorOf>
<name>allows http</name>
<url>http://here.it.is/repository/</url>
</mirror>
</mirrors>
</settings>
bom.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>org.myproject</groupId>
<artifactId>bom</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<repositories>
<repository>
<id>Private Repo</id>
<url>http://here.it.is/repository/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>codec</groupId>
<artifactId>codec</artifactId>
<version>1.10.0.</version>
</dependency>
</dependencies>
</project>
I followed the instructions from the official maven image on using /usr/share/maven/ref/repository for preloaded dependencies. The image builds successfully and when I start it I can see my dependency in both /usr/share/maven/ref/repository and in /root/.m2/repository.
Despite this when I run maven, it will always attempt to connect to my private repository. Is this some maven behavior I don't know about or is it ignoring my repository?
I believe you have faced with "enhanced local repository manager" feature:
Enhanced local repository manager is built upon the classical Maven
2.0 local repository structure but additionally keeps track of from what repositories a cached artifact was resolved. Resolution of
locally cached artifacts will be rejected in case the current
resolution request does not match the known source repositories of an
artifact, thereby emulating physically separated artifact caches per
remote repository.
For example:
% cat ~/.m2/repository/org/springframework/spring-core/5.3.9/_remote.repositories
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Wed Mar 16 08:49:28 AEDT 2022
spring-core-5.3.9.pom>internal-repository=
spring-core-5.3.9.pom>central=
spring-core-5.3.9.jar>central=
spring-core-5.3.9.jar>internal-repository=
You may either disable that feature via specifying -llr in maven opts or investigate how force maven to use the same "repository id" in different scenarios.

Locally installed jar not seen by maven

I have source code for a framework, let's call it my-framework. It provides various packages, including com.not_telling.framework.db.
I have a pom.xml file for this framework:
<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.not_telling</groupId>
<artifactId>my-famework</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>my-framework Maven Library</name>
<url>http://maven.apache.org</url>
<!-- more things here... -->
</project>
I can compile this and install it to my local repository cache, using this command:
mvn install
End of the install log:
[INFO] Installing C:\Users\MyUserName\my-framework\backend\target\my-framework.jar to C:\Users\MyUserName\.m2\repository\com\not_telling\my-famework\0.0.1-SNAPSHOT\my-famework-0.0.1-SNAPSHOT.jar
[INFO] Installing C:\Users\MyUserName\my-framework\backend\pom.xml to C:\Users\MyUserName\.m2\repository\com\not_telling\my-famework\0.0.1-SNAPSHOT\my-famework-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
Then I have another project, that tries to use this as a dependency:
<dependency>
<groupId>com.not_telling</groupId>
<artifactId>my-famework</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
The compilation phase of this project fails with this message:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project my-project: Compilation failure: Compilation failure:
[ERROR] /C:/Users/MyUserName/workspace/my-project/backend/src/main/java/com/not_telling/some_example.java:[13,17] package com.not_telling.framework.db does not exist
Why is that? Maybe because the jar is in the repository cache, but not in a local repository?
This question is a follow up of absolute maven pomderived entry added to classpath - I realized that instead of doing magic with relative source directory references, I need to make a separate module, but I'm facing this problem.
It was bleeding from numerous wounds. These needed to be fixed:
move source files from under src/ to under src/main/java, in both the framework and the application project
change the group and the artifact id to match the package name E.g. for a package that is named "com.not_telling.framework" I had to use groupId=com.not_telling and name=framework.
The dependency scope was wrong in the application's pom file. I had to remove test
Now it works from command line I can do "mvn install" for the framework, and then "mvn package" for the applications.
The only problem left is that the application cannot be compiled from eclipse, I had to remove all linked source folders / build paths in the application project to the framework.

How to download source code from Maven Central for a project

I want to download the source code for the project XBee-api v9.3 from Maven Central so that I can modify the code for my application. I am using Netbeans and I have managed to produce a POM that validates and compiles successfully.
I have then run the command
mvn dependency:resources
from the same directory as the POM to force download of the source code.
I have a few problems:
When I look inside the project with Netbeans, I see the class files (which I think may actually be jars). When I open up any class, I only get the method headers, but not the source code.
When I open a class file, there is the option in the top right of the window to "Attach Sources...". When I select "Download", I get a message in the lower left of the window saying "Downloading source jar from known Maven Repositories for local repository file" but nothing seems to be happening.
When I open up the folder either with explorer or Netbeans files view, the folder is empty except for the POM. If I use Projects view in Netbeans, I can see a project structure and what appears to be the generated source files, but no source code.
I can't find answers on Google.
My questions are:
What am I doing wrong?
How do I download the source code?
Any help would be much appreciated.
<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.rapplogic</groupId>
<artifactId>xbee-api</artifactId>
<packaging>jar</packaging>
<version>0.9.3</version>
<name>${project.groupId}:${project.artifactId}</name>
<description>A java library for communicating with XBee radios</description>
<url>https://github.com/andrewrapp/xbee-api/</url>
<licenses>
<license>
<name>GPL license, Version 3.0</name>
<url>https://www.gnu.org/licenses/gpl-3.0.html</url>
</license>
</licenses>
<developers>
<developer>
<name>Andrew Rapp</name>
<email>andrew.rapp+github.com#gmail.com</email>
</developer>
</developers>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<!-- https://mvnrepository.com/artifact/com.rapplogic/xbee-api -->
<dependencies>
<dependency>
<groupId>com.rapplogic</groupId>
<artifactId>xbee-api</artifactId>
<version>0.9.3</version>
</dependency>
</dependencies>
</project>
The GitHub project page is here:
https://github.com/andrewrapp/xbee-api
(referenced in the POM under the url element)
...so you can just download the source from the Github page: https://github.com/andrewrapp/xbee-api/archive/master.zip

Gradle mavenDeployer - how to include a separate modules code

I have a project like this:
MyProject
|-ModuleA
|-ModuleB
Module A is an Android Library that creates an aar, it has a dependency on Module B like so:
dependencies {
compile project(':ModuleB')
In ModuleA I am using mavenDepoyer to release locally:
uploadArchives {
repositories.mavenDeployer {
pom.groupId = "com.foo"
pom.artifactId = "bar"
pom.version = "1.0"
repository(url: "file://${localReleaseDest}")
}
}
This generates me an AAR file and a POM.
When uncompressed the AAR does not contain the class files from Module B
and the POM looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.foo</groupId>
<artifactId>bar</artifactId>
<version>1.0</version>
<packaging>aar</packaging>
<dependencies>
<dependency>
<groupId>MyProject</groupId>
<artifactId>ModuleB</artifactId>
<version>unspecified</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
As you can see this declares that the AAR has a dependency on ModuleB with an unspecified version. And so if I use this this AAR/POM as a remote, it fails to resolve the dependency ModuleB.
Error:A problem occurred configuring project ':example'.
Could not resolve all dependencies for configuration ':example:_debugCompile'.
Could not find MyProject:ModuleB:unspecified.
Searched in the following locations:
https://jcenter.bintray.com/MyProject/ModuleB/unspecified/ModuleB-unspecified.pom
https://jcenter.bintray.com/MyProject/ModuleB/unspecified/ModuleB-unspecified.jar
Required by:
Test:example:unspecified > com.foo:MyProject:1.0
I do not want it to try and resolve Module B as another dependency, I want to use the mavenDeployer to be able to create the AAR & POM with Module B included inside, since I have the source code here to do that!
Searched the web to no avail, these sites gave hints but no answer:
How to publish apks to the Maven Central with gradle?
how to tell gradle to build and upload archives of dependent projects to local maven
http://www.gradle.org/docs/current/userguide/artifact_management.html
http://gradle.org/docs/current/userguide/userguide_single.html#sub:multiple_artifacts_per_project
http://gradle.org/docs/current/userguide/userguide_single.html#deployerConfig
As far as I know, AARs don't include their dependencies (only APKs do). Instead, transitive dependency resolution will take care of resolving not only the AAR but also its dependencies. The unspecified version is most likely a result of not setting the project.version property in ModuleB.
<dependency>
<groupId>MyProject</groupId>
<artifactId>ModuleB</artifactId>
<version>unspecified</version>
<scope>compile</scope>
</dependency>
The reason is your module dependencies is below :
compile project(':module B')
to resolve this issue, you should dependens maven dep
compile 'com.xxxxxx.xxx:xxxxx:1.0.0-SHNAPSHOT'

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