Maven (IntelliJ) always using remote repository for artifacts - java

I have 2 maven projects where one depends on another. Let's call them common and service.
service specifically depends on a module within common we'll call common-module.
If I make an update to common-module and run mvn clean install, it gets properly installed to my local repository.
Problem
In service, when I do a mvn clean package/install or mvn -U clean package/install will pick up the version that's in the remote repository even though the one I just built is newer. I cannot get it to pick up that latest version even though I see it in my .m2/repository.
How can I get it to pick my locally built jar?
Setup
pom.xml for common (simplified, a lot is excluded)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<artifactId>common-parent</artifactId>
<version>2.4.5-SNAPSHOT</version>
<name>Common Parent</name>
<modules>
<module>common-module</module>
</modules>
</project>
pom.xml for common-module (simplified, a lot is excluded)
<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">
<artifactId>common-module</artifactId>
<name>common-module</name>
<description>common-module</description>
<parent>
<artifactId>common-parent</artifactId>
<groupId>com.company.group</groupId>
<version>2.4.5-SNAPSHOT</version>
</parent>
</project>
pom.xml for service (simplified, a lot is excluded)
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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">
<artifactId>service</artifactId>
<name>service</name>
<version>1.2.3-SNAPSHOT</version>
<dependencies>
<dependency>
<artifactId>common-module</artifactId>
<groupId>com.company.group</groupId>
<version>2.4.5-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Note 1: I have a workaround where I can adjust the library settings within IntelliJ and force it to use the correct jar file, but this feels very hacky and unsustainable to me.
Note 2: I've tried changing the <updatePolicy> value in my settings.xml to never and other values, but it seems to have had no effect. This was suggested in other posts I've read before asking here.
<repository>
<id>snapshots</id>
<name>Archiva Managed Snapshot Repository</name>
<url>http://internal.url/repository/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>

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.

Cannot determine why dependency pom.xml is considered invalid

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>

maven fetching dependency from incorrect location

Using this tutorial, I am trying to host a dependency on GitHub and then use the dependency in a separate application.
The dependency is located at:
https://github.com/user/repo/raw/master/release/tld/company/app/1.0.0/app-1.0.0.jar
However. maven keeps going to:
https://github.com/user/repo/raw/master/release/tld/company/app/app/1.0.0/app-1.0.0.pom
In my pom where I'm calling the dependency, I have:
<repositories>
<repository>
<id>tld.company</id>
<name>app</name>
<url>https://github.com/user/repo/raw/master/release/</url>
</repository>
</repositories>
and:
<dependency>
<groupId>tld.company.app</groupId>
<artifactId>app</artifactId>
<version>1.0.0</version>
</dependency>
In /master/company/release/tld/company/app/maven-metadata-local.xml I have:
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>tld.company.app</groupId>
<artifactId>app</artifactId>
<versioning>
<release>1.0.0</release>
<versions>
<version>1.0.0</version>
</versions>
<lastUpdated>20160233354414</lastUpdated>
</versioning>
</metadata>
In /master/company/release/tld/company/app/1.0.0/app-1.0.0.pom I have:
<?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>tld.company.app</groupId>
<artifactId>app</artifactId>
<version>1.0.0</version>
<description>POM was created from install:install-file</description>
</project>
What is the reason for the additional /app in the dependency download URL?
The group id should be tld.company, not tld.company.app. This explains your second app.
<dependency>
<groupId>tld.company</groupId>
<artifactId>app</artifactId>
<version>1.0.0</version>
</dependency>
Basically, when you have a URL from a repository of the following form, this is how it is understood by Maven:
https://someserver.com/.../tld/company/app/1.0.0/app-1.0.0.jar
^---------^ ^-^ ^---^ ^-----------^
groupId | version file name
artifactId
The last part if the file name which is ${artifactId}-${version}.
Before that is the version.
Before that is the artifact id.
And all the path before that are the group id, where slashes are replaced by dots.

maven-release-plugin deploying SNAPSHOT

I have a Maven project and now want to release it with the maven-release-plugin. Unfortunately after executing mvn release:prepare the git tag contains the old version number (1.0-SNAPSHOT) and when deploying to artifactory the SNAPSHOT version is used instead of the desired release version.
I already found this bug, but all suggested solutions are not working for me.
I'm using:
Apache Maven 3.3.9
git version 2.7.0 (German)
I already tried several versions of the release plugin (2.4, 2.5.3, 2.5.1) but none woked.
Does anyone have a fix for that problem?
EDIT1: The current 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>mygroupid</groupId>
<artifactId>myartifact</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- [...] -->
<scm>
<url>http://url/to/gitlab</url>
<connection>scm:git:git#gitlab:group/repo.git</connection>
<developerConnection>scm:git:git#gitlab:group/repo.git</developerConnection>
<tag>HEAD</tag>
</scm>
<!-- [...] -->
<distributionManagement>
<!-- [...] -->
</distributionManagement>
</project>

How do I get IntelliJ IDEA to import RinSim from Maven correctly?

I am trying to import RinSim 3.2.2 from Maven using IntelliJ IDEA. I'm running Windows 8.1 x64. The following is my 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>be.kuleuven.cs</groupId>
<artifactId>Multi-Agent_Systems</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.github.rinde</groupId>
<artifactId>rinsim-example</artifactId>
<version>3.2.2</version>
</dependency>
</dependencies>
</project>
The same POM file imports the library correctly in Eclipse, but when calling the Reimport function from within IntelliJ it resolves the dependencies incorrectly. The library depends on the SWT UI library, which is platform dependent. IntelliJ imports the 32-bit version on Windows instead of the 64-bit version. The architecture is selected using profiles in the POM file of RinSim's UI library.
I hacked around this issue by modifying my POM file to hardcode in the 64-bit dependency, but this is not a clean solution.
<?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>be.kuleuven.cs</groupId>
<artifactId>Multi-Agent_Systems</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.eclipse.swt</groupId>
<artifactId>org.eclipse.swt.win32.win32.x86_64</artifactId>
<version>4.4</version>
</dependency>
<dependency>
<groupId>com.github.rinde</groupId>
<artifactId>rinsim-example</artifactId>
<version>3.2.2</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.swt</groupId>
<artifactId>org.eclipse.swt.win32.win32.x86</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>swt-repo</id>
<name>SWT Repo</name>
<url>https://swt-repo.googlecode.com/svn/repo/</url>
</repository>
</repositories>
</project>
I'm trying to find out what causes the issue, the library's POM file seems to be correct. Perhaps IntelliJ has a bug causing this behavior, but I am unsure if that's the case.
I hope someone can offer me a solution to this problem or help me figure out the cause of the issue.
The problem is that IntelliJ is running on a bundled 32-bit JVM by default.
Use the idea64.exe instead of the idea.exe. The executables can be found in C:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.x.x\bin.
I tried it out and it works as expected.

Categories