Cannot determine why dependency pom.xml is considered invalid - java

Working with proprietary source code. Some dependencies are stored in a local (e.g. on my filesystem) maven repo, which is exposed in my main project pom.xml like so:
<repository>
<!-- Embed mvn repo with non-public dependencies -->
<id>myproj.local</id>
<url>file:${basedir}/src/repo</url>
<name>MyProj Embedded Repo</name>
<releases>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
This worked OK until today, when I added a new jar file into the embedded repo under src/repo/com/hidden/v2/some-api/1.5.0/some-api-1.5.0.jar and a new handcrafted pom at src/repo/com/hidden/v2/some-api/1.5.0/some-api-1.5.0.pom.
Now my code builds and runs OK, but I constantly get this error from maven and cannot figure out why:
[WARNING] The POM for com.hidden.v2:some-api:jar:1.5.0 is invalid, transitive dependencies (if any) will not be available: 2 problems were encountered while building the effective model for :some-api:1.5.0
[ERROR] 'groupId' is missing. # [unknown-group-id]:some-api:1.5.0
[ERROR] 'dependencies.dependency.version' for javax.servlet:servlet-api:jar is missing. # [unknown-group-id]:some-api:1.5.0
My custom pom file seems to have the fields that are supposedly missing:
<?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.hidden.v2</groupId>
<artifactId>some-api</artifactId>
<version>1.5.0</version>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<!-- <scope>provided</scope> -->
<version>2.5</version>
</dependency>
</dependencies>
</project>

Related

mvn build keeps checking nexus repos not matter what I put in pom file

I am trying to access some jar files by including dependencies in the pom. The problem is I get error not found in my corporate nexus repo. How do I tell Maven not to look only in http://sl-quality.mycompany.com/nexus/content/groups/public/ for the dependencies? And where earth is the url defined?
Could not resolve dependencies for project com.mycompany.myproj:mycompany-service:jar:1.0-
SNAPSHOT: Could not find artifact io.confluent.ksql:ksqldb-api-client:jar:0.11.0 in nexus
(http://sl-quality.mycompany.com/nexus/content/groups/public/
<?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.mycompany.myapp</groupId>
<artifactId>com-mycompany-app</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<ksqldb.version>0.11.0</ksqldb.version>
<!-- Maven properties for compilation -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<repositories>
<!-- jhipster-needle-maven-repository -->
<repository>
<id>ksqlDB</id>
<name>ksqlDB</name>
<url>https://ksqldb-maven.s3.amazonaws.com/maven/</url>
</repository>
<repository>
<id>confluent</id>
<name>Confluent</name>
<url>https://jenkins-confluent-packages-beta-maven.s3.amazonaws.com/6.1.0-beta200715032424/1/maven/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.confluent.ksql</groupId>
<artifactId>ksqldb-api-client</artifactId>
<version>${ksqldb.version}</version>
</dependency>
</dependencies>
I have no idea why it always goes to nexus as this is no where mentioned in my pom file. I could install in my local repo but not sure what app jar files need to be pulled for it to work as two repos needed to be added.
I would like to know exactly what jar files i can extract to put in my local repo. Thanks
Repository is generally configured in your settings file located in C:/Users/Youruser/.m2/settings.xml on windows
Check the mirror and corresponding repository tags for example - your settings.xml will probably look like this
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://sl-quality.mycompany.com/nexus/content/groups/public/</url>
</mirror>
Change this url to point to another repo, perhaps an external non corporate one such as http://repo.maven.apache.org/maven2
EDIT:
I think this is what you want
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*,!ksqlDB</mirrorOf>
<url>http://sl-quality.mycompany.com/nexus/content/groups/public/</url>
</mirror>
</mirrors>
<!-- Add repository for your other repo to filter on above -->
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>ksqlDB</id>
<url>https://ksqldb-maven.s3.amazonaws.com/maven/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</profile>
<!-- add at bottom inside </settings> -->
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
Add more repos as needed and filter above where necessary. I believe (not tested) that you can apply the same exclusions to mirrors instead of repositories personally I prefer using repository tags and having profiles setup.

Why does the setup of a simple project with Maven and Hibernate fail?

It is a simple project that consists of making a MySQL query and displaying it. I use NetBeans. The hibernate.xml and client.xml file were created by NetBeans (Hibernate Configuration Wizard and Hibernate Mapping Wizard). I really have no idea what the problem is.
1) POM file:
<?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.mycompany</groupId>
<artifactId>alsoMaven</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.5</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.10.Final</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
2) Main Class:
public static void main(String[] args) {
StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.configure() // obtiene los valores de hibernate.cfg.xml
.build();
try {
SessionFactory sessionFactory = new MetadataSources(registry)
.buildMetadata().buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
Cliente c = (Cliente) session.load(Cliente.class, 1);
System.out.println(c);
session.getTransaction().commit();
session.close();
sessionFactory.close();
} catch (Exception e) {
e.printStackTrace();
}
}
3) Exception:
------------------------------------------------------------------------
Building alsoMaven 1.0-SNAPSHOT
------------------------------------------------------------------------
Downloading: http://repo.maven.apache.org/maven2/org/jboss/spec/javax/transaction/jboss-transaction-api_1.2_spec/1.1.1.Final/jboss-transaction-api_1.2_spec-1.1.1.Final.jar
Downloading: http://repo.maven.apache.org/maven2/org/javassist/javassist/3.24.0-GA/javassist-3.24.0-GA.jar
Downloading: http://repo.maven.apache.org/maven2/org/jboss/logging/jboss-logging/3.3.2.Final/jboss-logging-3.3.2.Final.jar
Downloading: http://repo.maven.apache.org/maven2/org/hibernate/common/hibernate-commons-annotations/5.1.0.Final/hibernate-commons-annotations-5.1.0.Final.jar
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 3.184s
Finished at: Sun Mar 08 21:10:54 GMT-03:00 2020
Final Memory: 6M/16M
------------------------------------------------------------------------
Failed to execute goal on project alsoMaven: Could not resolve dependencies for project com.mycompany:alsoMaven:jar:1.0-SNAPSHOT: The following artifacts could not be resolved: org.jboss.logging:jboss-logging:jar:3.3.2.Final, org.javassist:javassist:jar:3.24.0-GA, org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.1.1.Final, org.hibernate.common:hibernate-commons-annotations:jar:5.1.0.Final: Could not transfer artifact org.jboss.logging:jboss-logging:jar:3.3.2.Final from/to central (http://repo.maven.apache.org/maven2): Failed to transfer file: http://repo.maven.apache.org/maven2/org/jboss/logging/jboss-logging/3.3.2.Final/jboss-logging-3.3.2.Final.jar. Return code is: 501 , ReasonPhrase:HTTPS Required. -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
Thx!
Starting 15 January 2020, the Maven Central repository doesn't support insecure communication over plain HTTP. You have to adjust your local configuration.
With this in mind, we find an important detail in the error message:
Return code is: 501, ReasonPhrase:HTTPS Required.
As we can see in the output, you are still using plain, un-encrypted connections to query/retrieve artefacts from Maven Central:
Downloading: http://repo.maven.apache.org/maven2/org/jboss/spec/javax/transaction/jboss-transaction-api_1.2_spec/1.1.1.Final/jboss-transaction-api_1.2_spec-1.1.1.Final.jar
...
Make sure that your local settings.xml contains only entries with https for the Maven central repositories in it. Consequently, the entry http://repo.maven.apache.org/maven2/ must be changed into https://repo.maven.apache.org/maven2/.
A minimal working configuration reads as follows:
<profile>
<id>maven-https</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
Hope it helps.
You might need to add proxy in settings.xml as shown below
<proxies>
<proxy>
<id>optional</id>
<active>true</active>
<protocol>https</protocol>
<username>abc</</username>
<password>abc123</password>
<host>webproxy.company.com</host>
<port>8081</port>
<!-- <nonProxyHosts>local.net|some.host.com</nonProxyHosts> -->
</proxy>
</proxies>

Install maven dependency from location other than Maven Central

I have this pom.xml file:
<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>interos</groupId>
<artifactId>jenkins</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>Maven Quick Start Archetype</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>cli</artifactId>
<version>2.49</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jenkins-ci.main/cli -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
I run
mvn install
and I get:
[ERROR] Failed to execute goal on project jenkins: Could not resolve
dependencies for project interos:jenkins:jar:1.0: Failure to find
org.jenkins-ci.main:cli:jar:2.49 in
https://repo.maven.apache.org/maven2 was cached in the local
repository, resolution will not be reattempted until the update
interval of central has elapsed or updates are forced -> [Help 1]
http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
I tried doing this:
<repositories>
<repository>
<id>repository.maven</id>
<name>Spring Framework Maven Release Repository</name>
<url>https://mvnrepository.com</url>
</repository>
</repositories>
But then I got:
[ERROR] Failed to execute goal on project jenkins: Could not resolve
dependencies for project interos:jenkins:jar:1.0: Could not find
artifact org.jenkins-ci.main:cli:jar:2.49 in repository.maven
(https://mvnrepository.com) -> [Help 1]
You need to add jenkins repository
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
There are 2 possible solutions (perhaps more):
Add also Maven central to the repositories section of your pom file.
Add repositories and mirrors to the Maven settings.xml file.
Option 1 and 2 can also be combined.
Another but maybe the best solution is to use your own instance of a Nexus repository manager and load all the dependencies from that Nexus instance (that Nexus should be defined as repository). That Nexus instance should synchronize with/proxy to external repositories like Maven central, Spring, ... and so on.

How to include dependencies targeting JDK 1.8 in jenkins plugin?

I have followed the official tutorial for creating Jenkins plugins: I have run mvn -U org.jenkins-ci.tools:maven-hpi-plugin:create to generate initial POM
Then I added guava as a dependency.
However, when I perform mvn package I get:
[INFO] --- maven-enforcer-plugin:1.4.2.jenkins-1:enforce (display-info) # flaky-tests ---
[INFO] Restricted to JDK 1.7 yet com.google.guava:guava:jar:22.0:compile contains com/google/common/annotations/Beta.class targeted to JDK 1.8
...
[WARNING] Rule 2: org.apache.maven.plugins.enforcer.EnforceBytecodeVersion failed with message:
Found Banned Dependency: com.google.guava:guava:jar:22.0
Use 'mvn dependency:tree' to locate the source of the banned dependencies.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
How can I include dependencies targeting JDK 1.8 in my Jenkins plugin?
Here's my full 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.32</version>
<relativePath/>
</parent>
<groupId>com.github.dzieciou.testing</groupId>
<artifactId>flaky-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>hpi</packaging>
<properties>
<jenkins.version>2.68</jenkins.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>22.0</version>
</dependency>
</dependencies>
</project>
It was enough to add the following property to POM:
<java.level>8</java.level>

Maven dependency for pd4ml

HI I searched on google and did not find the dependency for PD4ML.I have added the jar manually but everytime i do mvn clean install it is giving me compile time error
error: package org.zefer.pd4ml does not exist
org.zefer.pd4ml does not exist
I got the answer after hours spending on it
step one :download the pd4ml.jar
step two :Run the below command on command prompt
mvn install:install-file -Dfile=D:\<path to your downloaded jar>\pd4ml.jar -DgroupId=com.pd4ml.utilities -DartifactId=pd4ml -Dversion=1.0 -Dpackaging=jar
step 3 : add the dependency on pom.xml based on the groupId and artifactsId you have provided
<dependency>
<groupId>com.pd4ml.utilities</groupId>
<artifactId>pd4ml</artifactId>
<version>1.0</version>
</dependency>
Remember ss_css2 jar is also require to run the pd4ml follow the above steps to create a mvn depedency for this jar
Did you add a dependency to the pom.xml file?
Something like:
<dependency>
<groupId>org.zefer.pd4ml</groupId>
<artifactId>pd4ml</artifactId>
<version>3.2.3fx5</version>
</dependency>
In your pom.xml add the repository first to resolve the pd4ml as below:
<repositories>
<repository>
<id>my-repo2</id>
<name>your custom repo</name>
<url>http://maven.scandilabs.com/repository</url>
</repository>
</repositories>
and then in the dependencies add dependency as below:
<dependency>
groupId>org.zefer.pd4ml</groupId>
<artifactId>pd4ml</artifactId>
<version>370fx2</version>
</dependency>
Add the repository https://pd4ml.tech/maven2/ and the dependency com.pd4ml to your pom.xml:
<project ...>
<groupId>de.luckydonald.stackoverflow</groupId>
<artifactId>42805145</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>pd4ml</id>
<url>https://pd4ml.tech/maven2/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<!-- html to rtf -->
<dependency>
<groupId>com.pd4ml</groupId>
<artifactId>pd4ml</artifactId>
<version>4.0.2</version>
</dependency>
</dependencies>
</project>

Categories