您可能想根据您想要使用的覆盖工具修改自己的 pom.xml,请参阅https://github.com/trautonen/coveralls-maven-plugin以获得一些解释。
您可以避免将 repo 令牌放在您在 github 上发布的 pom.xml 文件中!
相反,您可以从命令行运行覆盖率报告。
这是一个小的帮助脚本,允许从命令行运行 converalls。只需将您的令牌放在 $HOME/.coveralls 之类的地方或任何类似位置即可。
#!/bin/bash
# WF 2019-06-26
# create test coverage report for coveralls
tokenpath=$HOME/.coveralls/coveralls.token
if [ ! -f $tokenpath ]
then
echo "Script needs coveralls token in $tokenpath to work" 1>&2
echo "Script can only be run successfully by project admins" 1>&2
echo "see https://github.com/trautonen/coveralls-maven-plugin" 1>&2
exit 1
else
token=$(cat $tokenpath)
# comment out to use jacoco
#mvn clean test jacoco:report coveralls:report -D jacoco=true -DrepoToken=$token
# comment out to use cobertura
mvn cobertura:cobertura coveralls:report -DrepoToken=$token
fi
更新
这里是使用 COVERALLS_TOKEN 环境变量的版本:
#!/bin/bash
# WF 2019-06-26
# create test coverage report for coveralls
# is the environment variable not set?
if [ "$COVERALLS_TOKEN" = "" ]
then
tokenpath=$HOME/.dukes/coveralls.token
if [ ! -f $tokenpath ]
then
echo "Script needs coveralls token in $tokenpath to or COVERALLS_TOKEN environment variable to work" 1>&2
echo "Script can only be run successfully by project admins" 1>&2
echo "see https://github.com/trautonen/coveralls-maven-plugin" 1>&2
echo "see https://stackoverflow.com/a/56815300/1497139" 1>&2
exit 1
fi
else
export COVERALLS_TOKEN=$(cat $tokenpath)
fi
# the jacoco variable tries triggering a profile - check your pom.xml
# for any profile being in use
mvn clean test jacoco:report coveralls:report -D jacoco=true
#mvn clean test jacoco:report coveralls:report -D jacoco=true -DrepoToken=$token
#mvn cobertura:cobertura coveralls:report
#mvn cobertura:cobertura coveralls:report -DrepoToken=$COVERALLS_TOKEN