Issue
I have two projects:
- An Eclipse project build with pomless Tycho approach
- A plain Java project build with plain Maven, no OSGI, no Tycho
I need to use some of the bundles from the 1st project in the 2nd project. I tried to install the jar files from the 1st project into a local maven repository using mvn clean install
. And tried to reference them from the 2nd project. But I get the following error:
Failed to execute goal on project ...: Could not resolve dependencies for project ...: Failed to collect dependencies at bpms:bpms.util.jdk:jar:0.1.0-SNAPSHOT: Failed to read artifact descriptor for bpms:bpms.util.jdk:jar:0.1.0-SNAPSHOT: Failure to find bpms:bundles:pom:1.0.0-SNAPSHOT in https://repo.maven.apache.org/maven2 was cached in the local repository, the resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
The bpms.util.jdk-0.1.0-SNAPSHOT.pom
file contains the following:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://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>
<parent>
<groupId>bpms</groupId>
<artifactId>bundles</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..\.polyglot.pom.tycho</relativePath>
</parent>
<artifactId>bpms.util.jdk</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>jdk utils</name>
</project>
It seems that the problem is caused by the parent artifact. Is it possible to install my artifacts as standalone artifacts without reference to parent bundles
?
What is the right approach? I can't use a pomless Tycho and should define a separate pom.xml for each bundle?
Solution
It seems that the simplest approach is to install jar files using mvn install:install-file
. Here is a bat-file that could be useful for someone:
@echo off
set MVN_HOME=C:/Tools/apache-maven-3.6.3
set BUNDLES_HOME=C:/Work/workspace-bpms-trunk/bundles
set ECLIPSE_HOME=C:/Tools/eclipse/plugins
set PATH=%MVN_HOME%/bin;%PATH%
for /f "tokens=1,2 delims=:" %%E in (deps.txt) do (
if exist %BUNDLES_HOME%/%%F (
for /f "tokens=1,2 delims=: " %%G in (%BUNDLES_HOME%/%%F/META-INF/MANIFEST.MF) do (
if "%%G" == "Bundle-Version" (
call mvn install:install-file -DgroupId=%%E -DartifactId=%%F -Dversion=%%~nH-SNAPSHOT -DgeneratePom=true -Dpackaging=jar -Dfile="%BUNDLES_HOME%/%%F/target/%%F-%%~nH-SNAPSHOT.jar"
)
)
) else (
for %%G in (%ECLIPSE_HOME%/%%F_*.jar) do (
for /f "tokens=2 delims=_" %%H in ("%%~nG") do (
call mvn install:install-file -DgroupId=%%E -DartifactId=%%F -Dversion=%%H -DgeneratePom=true -Dpackaging=jar -Dfile="%ECLIPSE_HOME%/%%~nG.jar"
)
)
)
)
It reads groupId
and artifactId
from deps.txt
file of the following format:
org.eclipse.ocl:org.eclipse.ocl
org.eclipse.ocl:org.eclipse.ocl.common
org.eclipse.ocl:org.eclipse.ocl.ecore
org.eclipse.ocl:org.eclipse.ocl.pivot
At first it tries to find a bundle in BUNDLES_HOME
. If found then it reads a bundle version from META-INF/MANIFEST.MF
and installs jar into a local maven repository. pom-files are generated.
If the bundle not found in BUNDLES_HOME
then it tries to find it in ECLIPSE_HOME
.
The second script reads deps.txt
and generates a list of dependencies for pom.xml
:
@echo off
set BUNDLES_HOME=C:/Work/workspace-bpms-trunk/bundles
set ECLIPSE_HOME=C:/Tools/eclipse/plugins
break > deps-gen.txt
for /f "tokens=1,2 delims=:" %%E in (deps.txt) do (
if exist %BUNDLES_HOME%/%%F (
for /f "tokens=1,2 delims=: " %%G in (%BUNDLES_HOME%/%%F/META-INF/MANIFEST.MF) do (
if "%%G" == "Bundle-Version" (
echo ^<dependency^>>> deps-gen.txt
echo ^<groupId^>%%E^</groupId^>>> deps-gen.txt
echo ^<artifactId^>%%F^</artifactId^>>> deps-gen.txt
echo ^<version^>%%~nH-SNAPSHOT^</version^>>> deps-gen.txt
echo ^</dependency^>>> deps-gen.txt
)
)
) else (
for %%G in (%ECLIPSE_HOME%/%%F_*.jar) do (
for /f "tokens=2 delims=_" %%H in ("%%~nG") do (
echo ^<dependency^>>> deps-gen.txt
echo ^<groupId^>%%E^</groupId^>>> deps-gen.txt
echo ^<artifactId^>%%F^</artifactId^>>> deps-gen.txt
echo ^<version^>%%H^</version^>>> deps-gen.txt
echo ^</dependency^>>> deps-gen.txt
)
)
)
)
A similar installer for Linux:
#!/bin/bash
BUNDLES_HOME=~/workspaces/workspace-bpms-trunk/bundles
ECLIPSE_PLUGINS=~/.p2/pool/plugins
while IFS=":" read -r group artifact || [ -n "$p" ]; do
artifact="${artifact//[$'\r\n']}"
if [ "$artifact" = "" ]; then
:
elif [ -d "$BUNDLES_HOME/$artifact" ]; then
while IFS=":" read -r key value || [ -n "$p" ]; do
if [ "$key" = "Bundle-Version" ]; then
version="${value//[[:space:]]/}"
version="${version/.qualifier/-SNAPSHOT}"
mvn install:install-file -DgroupId=$group -DartifactId=$artifact \
-Dversion=$version -DgeneratePom=true -Dpackaging=jar \
-Dfile="$BUNDLES_HOME/$artifact/target/$artifact-$version.jar"
fi
done < "$BUNDLES_HOME/$artifact/META-INF/MANIFEST.MF"
else
for file in "$ECLIPSE_PLUGINS"/${artifact}_*.jar; do
version="${file%%.jar}"
version="${version##*_}"
mvn install:install-file -DgroupId=$group -DartifactId=$artifact \
-Dversion=$version -DgeneratePom=true -Dpackaging=jar -Dfile="$file"
done
fi
done < deps.txt
And pom-file dependency generator:
#!/bin/bash
BUNDLES_HOME=~/workspaces/workspace-bpms-trunk/bundles
ECLIPSE_PLUGINS=~/.p2/pool/plugins
: > deps-gen.txt
while IFS=":" read -r group artifact || [ -n "$p" ]; do
artifact="${artifact//[$'\r\n']}"
if [ "$artifact" = "" ]; then
echo >> deps-gen.txt
elif [ -d "$BUNDLES_HOME/$artifact" ]; then
while IFS=":" read -r key value || [ -n "$p" ]; do
if [ "$key" = "Bundle-Version" ]; then
version="${value//[[:space:]]/}"
version="${version/.qualifier/-SNAPSHOT}"
echo " <dependency>" >> deps-gen.txt
echo " <groupId>$group</groupId>" >> deps-gen.txt
echo " <artifactId>$artifact</artifactId>" >> deps-gen.txt
echo " <version>$version</version>" >> deps-gen.txt
echo " </dependency>" >> deps-gen.txt
fi
done < "$BUNDLES_HOME/$artifact/META-INF/MANIFEST.MF"
else
for file in "$ECLIPSE_PLUGINS"/${artifact}_*.jar; do
version="${file%%.jar}"
version="${version##*_}"
echo " <dependency>" >> deps-gen.txt
echo " <groupId>$group</groupId>" >> deps-gen.txt
echo " <artifactId>$artifact</artifactId>" >> deps-gen.txt
echo " <version>$version</version>" >> deps-gen.txt
echo " </dependency>" >> deps-gen.txt
done
fi
done < deps.txt
Answered By - Denis
Answer Checked By - Candace Johnson (JavaFixing Volunteer)