如何在非 tycho 项目中使用 pomless tycho 工件
How to use pomless tycho artifacts in non-tycho project
我有两个项目:
- 使用 pomless Tycho 方法构建的 Eclipse 项目
- 一个简单的 Java 项目构建,使用简单的 Maven,没有 OSGI,没有 Tycho
我需要在第二个项目中使用第一个项目中的一些包。我尝试使用 mvn clean install
将第一个项目的 jar 文件安装到本地 Maven 存储库中。并尝试从第二个项目中引用它们。但是我收到以下错误:
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]
bpms.util.jdk-0.1.0-SNAPSHOT.pom
文件包含以下内容:
<?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>
看来问题是由父神器引起的。是否可以在不参考父 bundles
的情况下将我的工件作为独立工件安装?
什么是正确的做法?我不能使用 pomless Tycho 并且应该为每个包定义一个单独的 pom.xml?
似乎最简单的方法是使用 mvn install:install-file
安装 jar 文件。这是一个可能对某人有用的 bat 文件:
@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"
)
)
)
)
它从以下格式的 deps.txt
文件中读取 groupId
和 artifactId
:
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
首先它试图在 BUNDLES_HOME
中找到一个包。如果找到,它会从 META-INF/MANIFEST.MF
中读取一个包版本并将 jar 安装到本地 maven 存储库中。生成 pom 文件。
如果在 BUNDLES_HOME
中找不到包,则它会尝试在 ECLIPSE_HOME
中找到它。
第二个脚本读取 deps.txt
并生成 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
)
)
)
)
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
和 pom 文件依赖生成器:
#!/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
我有两个项目:
- 使用 pomless Tycho 方法构建的 Eclipse 项目
- 一个简单的 Java 项目构建,使用简单的 Maven,没有 OSGI,没有 Tycho
我需要在第二个项目中使用第一个项目中的一些包。我尝试使用 mvn clean install
将第一个项目的 jar 文件安装到本地 Maven 存储库中。并尝试从第二个项目中引用它们。但是我收到以下错误:
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]
bpms.util.jdk-0.1.0-SNAPSHOT.pom
文件包含以下内容:
<?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>
看来问题是由父神器引起的。是否可以在不参考父 bundles
的情况下将我的工件作为独立工件安装?
什么是正确的做法?我不能使用 pomless Tycho 并且应该为每个包定义一个单独的 pom.xml?
似乎最简单的方法是使用 mvn install:install-file
安装 jar 文件。这是一个可能对某人有用的 bat 文件:
@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"
)
)
)
)
它从以下格式的 deps.txt
文件中读取 groupId
和 artifactId
:
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
首先它试图在 BUNDLES_HOME
中找到一个包。如果找到,它会从 META-INF/MANIFEST.MF
中读取一个包版本并将 jar 安装到本地 maven 存储库中。生成 pom 文件。
如果在 BUNDLES_HOME
中找不到包,则它会尝试在 ECLIPSE_HOME
中找到它。
第二个脚本读取 deps.txt
并生成 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
)
)
)
)
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
和 pom 文件依赖生成器:
#!/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