You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jenkins用户在构建节点运行测试时因缺失scala-library.jar失败的问题

Fixing Missing scala-library.jar When Running SBT Tasks as Jenkins User

Hey there, I’ve run into this exact kind of Jenkins + SBT permission/cache issue a few times. Let’s break down why this is happening and how to fix it:

Your root/local user can run the SBT command fine because it’s using the cached scala-library.jar in /root/.cache/coursier/, but the Jenkins user doesn’t have access to that directory. Add to that, SBT 0.13.x has some quirks with Coursier caching that can make this worse. Here are the most effective solutions:

Why This Happens

  • The Jenkins user lacks read permissions for the root user’s Coursier cache directory (/root/.cache/coursier/).
  • SBT might be trying to reuse root’s cached dependencies, but can’t access them.
  • Missing environment variables or SBT config for the Jenkins user could prevent proper dependency pulls from Artifactory.

Solutions to Try

1. Set Up a Coursier Cache for Jenkins User

First, give Jenkins its own cache directory so it doesn’t rely on root’s files:

  1. Switch to the Jenkins user on your build slave:
    sudo su - jenkins
    
  2. Create and secure the cache directory:
    mkdir -p ~/.cache/coursier/v1
    chmod -R 755 ~/.cache
    
  3. Manually trigger a dependency pull to populate the cache:
    /usr/lib/jvm/java-1.8.0/bin/java -Xmx4250M -Dsbt.log.noformat=true -jar /tmp/jenkins/slaves/build-slave-cb996aa/tools/org.jvnet.hudson.plugins.SbtPluginBuilder_SbtInstallation/default/bin/sbt-launch.jar update
    

This will download scala-library.jar (and other dependencies) into Jenkins’ own cache, so the assembly command can find it later.

2. Configure SBT Globally for Jenkins

Tweak SBT’s global config to use Jenkins’ cache and explicitly define repositories:

  1. As the Jenkins user, create an SBT repositories file:
    sudo su - jenkins
    mkdir -p ~/.sbt/0.13
    cat > ~/.sbt/0.13/repositories << EOF
    [repositories]
    local
    maven-central: https://repo1.maven.org/maven2/
    artifactory: $ARTIFACTORY_HOST
    EOF
    
  2. Add a cache path override to SBT options:
    echo "-Dsbt.coursier.cache=~/.cache/coursier" >> ~/.sbt/0.13/sbtopts
    

This tells SBT exactly where to store/retrieve dependencies for the Jenkins user.

3. Verify Jenkins’ Environment & Artifactory Access

Make sure Jenkins has the right environment variables and Artifactory permissions:

  • Add a step in your Jenkins job to print variables and test Artifactory access:
    echo "ARTIFACTORY_HOST: $ARTIFACTORY_HOST"
    echo "USER: $USER"
    # Test if Jenkins can reach Artifactory
    curl -u $USER:$PASSWORD $ARTIFACTORY_HOST/org/scala-lang/scala-library/2.11.11/
    

If the curl fails, fix the credentials or Artifactory permissions for the Jenkins user—sometimes a failed auth makes it look like a missing jar.

4. Clean & Rebuild Dependencies from Scratch

If all else fails, wipe Jenkins’ SBT/cache files and start fresh:

sudo su - jenkins
rm -rf ~/.sbt ~/.cache/coursier
# Run the full command to pull dependencies and assemble
/usr/lib/jvm/java-1.8.0/bin/java -Xmx4250M -Dsbt.log.noformat=true -jar /tmp/jenkins/slaves/build-slave-cb996aa/tools/org.jvnet.hudson.plugins.SbtPluginBuilder_SbtInstallation/default/bin/sbt-launch.jar 'set credentials += Credentials("Artifactory Realm", $ARTIFACTORY_HOST, $USER, $PASSWORD)' clean update assembly

Verify the Fix

After trying any of the above, test the command manually as the Jenkins user to confirm it works:

sudo su - jenkins
/usr/lib/jvm/java-1.8.0/bin/java -Xmx4250M -Dsbt.log.noformat=true -jar /tmp/jenkins/slaves/build-slave-cb996aa/tools/org.jvnet.hudson.plugins.SbtPluginBuilder_SbtInstallation/default/bin/sbt-launch.jar 'set credentials += Credentials("Artifactory Realm", $ARTIFACTORY_HOST, $USER, $PASSWORD)' assembly

内容的提问来源于stack exchange,提问作者Nir Orman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 09:28:36