我最初使用的是位于Central Maven存储库中的库。所以我只是将依赖项包含在IntelliJ中的pom文件中。
现在我需要稍微修改源代码然后我不得不重新编译外部库并在本地安装到我的.m2存储库中。在这种情况下,我是否需要从我的Pom中删除依赖项部分才能使用我自己编译的本地安装的jar文件?
编译和生成jar文件的脚本。我运行这个库源代码附带的脚本来编译和安装在本地。
#!/bin/bash -e
# helper function that ensures cmd returns 0 exit code
function checkexit {
"$@"
local status=$?
if [ $status -ne 0 ]; then
echo "error with $1" >&2
exit 1
fi
return $status
}
function maybeUpdateRepo {
if [ "$UPDATE_REPOS" == "true" ]; then
# are there uncommited changes in the repo?
if ! (git diff-index --quiet HEAD --) then
echo "Some uncommited changes found in this repo! Stashing..."
git stash
fi
git pull
fi
}
# check incoming parameters
while [[ $# -gt 1 ]]
do
key="$1"
#Build type (release/debug), packaging type, chip: cpu,gpu,lib type (static/dynamic)
case $key in
-c|--chip)
CHIP="$2"
shift # past argument
;;
-cc|--compute)
COMPUTE="$2"
shift # past argument
;;
-a|--march)
NATIVE="$2"
shift # past argument
;;
-l|--libtype)
LIBTYPE="$2"
shift # past argument
;;
--scalav)
SCALAV="$2"
shift # past argument
;;
-s|--shallow)
SHALLOW="YES"
;;
-r|--repostrategy)
REPO_STRATEGY="$2"
shift # past argument
;;
--deploy)
DEPLOY="YES"
;;
--testnd4j)
TEST_ND4J="YES"
;;
--testdatavec)
TEST_DATAVEC="YES"
;;
--testdl4j)
TEST_DL4J="YES"
;;
--skiplibnd4j)
SKIP_LIBND4J="YES"
;;
--skipnd4j)
SKIP_ND4J="YES"
;;
--skipdatavec)
SKIP_DATAVEC="YES"
;;
--skipdl4j)
SKIP_DL4J="YES"
;;
--mvnopts)
MVN_OPTS="$2"
shift
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
# default for chip
if [[ -z "$CHIP" ]]; then
# test for cuda libraries
if (type ldconfig &> /dev/null); then
if (ldconfig -p | grep -q libcuda\.so); then
CHIP="cuda"
else
CHIP="cpu"
fi
fi
fi
# adjust scala versions
if [ "$SCALAV" == "2.10" ]; then
SCALA="2.10.6"
fi
# adjust scala versions
if [ "$SCALAV" == "2.11" ]; then
SCALA="2.11.7"
fi
# set git cloning to a shallow depth if the option says so
if [[ -z "$SHALLOW" ]]; then
GIT_CLONE="git clone"
else
GIT_CLONE="git clone --depth 1"
fi
# set git cloning to a shallow depth if the option says so
if [[ -z "$DEPLOY" ]]; then
MVN_GOAL="install"
else
MVN_GOAL="deploy"
fi
# Report argument values
echo CHIP = "${CHIP}"
echo COMPUTE = "${COMPUTE}"
echo DEPLOY = "${DEPLOY}"
echo NATIVE = "${NATIVE}"
echo LIBTYPE = "${LIBTYPE}"
echo SCALAV = "${SCALAV}"
echo SHALLOW = "${SHALLOW}"
echo REPO_STRATEGY = "${REPO_STRATEGY}"
echo TEST_ND4J = "${TEST_ND4J}"
echo TEST_DATAVEC = "${TEST_DATAVEC}"
echo TEST_DL4J = "${TEST_DL4J}"
echo SKIP_LIBND4J = "${SKIP_LIBND4J}"
echo SKIP_ND4J = "${SKIP_ND4J}"
echo SKIP_DATAVEC = "${SKIP_DATAVEC}"
echo SKIP_DL4J = "${SKIP_DL4J}"
echo MVN_OPTS = "${MVN_OPTS}"
###########################
# Script execution starts #
###########################
pushd ..
# removes lingering snapshot artifacts from existing maven cache to ensure a
# clean build
JAVA_PROJECTS="nd4j datavec deeplearning4j"
for dirName in $JAVA_PROJECTS; do
if [ -d "$dirName" ]; then
pushd "$dirName"
mvn dependency:purge-local-repository -DreResolve=false -DactTransitively=false
popd
fi
done
# What to do with existing repos
case $REPO_STRATEGY in
"delete")
DELETE_REPOS="true"
UPDATE_REPOS=""
;;
"update")
UPDATE_REPOS="true"
DELETE_REPOS=""
;;
*) # unknown : do nothing
UPDATE_REPOS=""
DELETE_REPOS=""
;;
esac
# removes any existing repositories to ensure a clean build
if [[ ! (-z "$DELETE_REPOS") ]]; then
PROJECTS="libnd4j nd4j datavec deeplearning4j"
for dirName in $PROJECTS; do
find . -maxdepth 1 -iname "$dirName" -exec rm -rf "{}" \;
done
fi
# compile libnd4j
if [[ -z "$SKIP_LIBND4J" ]]; then
if [[ ! (-z "$DELETE_REPOS") || ! (-d libnd4j) ]]; then
checkexit $GIT_CLONE https://github.com/deeplearning4j/libnd4j.git
fi
pushd libnd4j
maybeUpdateRepo
if [[ -z "$NATIVE" ]]; then
checkexit bash buildnativeoperations.sh "$@" -a native
else
checkexit bash buildnativeoperations.sh "$@"
fi
if [ "$CHIP" == "cuda" ]; then
if [[ -z "$COMPUTE" ]]; then
checkexit bash buildnativeoperations.sh -c cuda
else
checkexit bash buildnativeoperations.sh -c cuda -cc "$COMPUTE"
fi
fi
LIBND4J_HOME=$(pwd)
export LIBND4J_HOME
popd
fi
# build and install nd4j to maven locally
if [[ -z "$SKIP_ND4J" ]]; then
if [[ ! (-z "$DELETE_REPOS") || ! (-d nd4j) ]]; then
checkexit $GIT_CLONE https://github.com/deeplearning4j/nd4j.git
fi
if [[ -z "$TEST_ND4J" ]]; then
ND4J_OPTIONS="-DskipTests"
else
ND4J_OPTIONS=""
fi
pushd nd4j
maybeUpdateRepo
if [ "$CHIP" == "cpu" ]; then
checkexit bash buildmultiplescalaversions.sh clean $MVN_GOAL -Dmaven.javadoc.skip=true -pl '!nd4j-backends/nd4j-backend-impls/nd4j-cuda,!nd4j-backends/nd4j-backend-impls/nd4j-cuda-platform,!nd4j-backends/nd4j-tests' $ND4J_OPTIONS $MVN_OPTS
else
checkexit bash buildmultiplescalaversions.sh clean $MVN_GOAL -Dmaven.javadoc.skip=true $ND4J_OPTIONS $MVN_OPTS
fi
popd
fi
# build and install datavec
if [[ -z "$SKIP_DATAVEC" ]]; then
if [[ ! (-z "$DELETE_REPOS") || ! (-d datavec) ]]; then
checkexit $GIT_CLONE https://github.com/deeplearning4j/datavec.git
fi
if [[ -z "$TEST_DATAVEC" ]]; then
DATAVEC_OPTIONS="-DskipTests"
else
if [ "$CHIP" == "cuda" ]; then
DATAVEC_OPTIONS="-Ptest-nd4j-cuda-8.0"
else
DATAVEC_OPTIONS="-Ptest-nd4j-native"
fi
fi
pushd datavec
maybeUpdateRepo
if [ "$SCALAV" == "" ]; then
checkexit bash buildmultiplescalaversions.sh clean $MVN_GOAL -Dmaven.javadoc.skip=true $DATAVEC_OPTIONS $MVN_OPTS
else
checkexit mvn clean $MVN_GOAL -Dmaven.javadoc.skip=true -Dscala.binary.version="$SCALAV" -Dscala.version="$SCALA" $DATAVEC_OPTIONS $MVN_OPTS
fi
popd
fi
# build and install deeplearning4j
if [[ -z "$SKIP_DL4J" ]]; then
if [[ ! (-z "$DELETE_REPOS") || ! (-d deeplearning4j) ]]; then
checkexit $GIT_CLONE https://github.com/deeplearning4j/deeplearning4j.git
fi
if [[ -z "$TEST_DL4J" ]] ; then
DL4J_OPTIONS="-DskipTests"
else
if [ "$CHIP" == "cuda" ]; then
DL4J_OPTIONS="-Ptest-nd4j-cuda-8.0"
else
DL4J_OPTIONS="-Ptest-nd4j-native"
fi
fi
pushd deeplearning4j
maybeUpdateRepo
if [ $DELETE_REPOS == "true" ]; then
# reset the working diectory to the latest version of the tracking branch
git remote update
TRACKING_BRANCH=$(git rev-parse --abbrev-ref --symbolic-full-name '@{u}')
git reset --hard "$TRACKING_BRANCH"
fi
if [ "$SCALAV" == "" ]; then
if [ "$CHIP" == "cpu" ]; then
checkexit bash buildmultiplescalaversions.sh clean $MVN_GOAL -Dmaven.javadoc.skip=true -pl '!./deeplearning4j-cuda/' $DL4J_OPTIONS $MVN_OPTS
else
checkexit bash buildmultiplescalaversions.sh clean $MVN_GOAL -Dmaven.javadoc.skip=true $DL4J_OPTIONS $MVN_OPTS
fi
else
checkexit mvn clean $MVN_GOAL -Dmaven.javadoc.skip=true -Dscala.binary.version="$SCALAV" -Dscala.version="$SCALA" $DL4J_OPTIONS $MVN_OPTS
fi
popd
fi
popd
答案 0 :(得分:1)
我建议您按照以下更好的做法和工作线:
现在我需要稍微修改源代码,然后我必须这样做 重新编译外部库并在本地安装到我的.m2中 库中。
您必须将其版本从x.y.z
更新为x.y.z+1-SNAPSHOT
以标记其更改,然后发布工件。我们现在就说你当地人。
注意 - SNAPSHOT
因为这似乎正在开发中,否则您也可以将更改标记为x.y.z+1
发布版本。
在这种情况下,我是否需要从Pom中删除依赖项部分 为了使用我编译的本地安装的jar文件 自己?
当您使用依赖项
时,现在在原始项目中<groupId>somegroup</groupId>
<artifactId>someartifactId</artifactId>
<version>x.y.z</version>
只需将版本更新为
<version>x.y.z+1-SNAPSHOT</version>
修改 :这可能有助于理解该方法,What exactly is a Maven Snapshot and why do we need it?