mvn can't use in cloud shell

修文 葉 5 Reputation points
2025-02-27T07:47:22.9466667+00:00

I use "mvn com.microsoft.azure:azure-webapp-maven-plugin:2.5.0:config"

but get the error message.

My project is Java spring boot project

use Java 8 SE

(I don't thing the problem is on my project because some of mvn doesn't work)

It's work before January.

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableSet

    at com.google.inject.internal.Errors.<clinit>(Errors.java:105)

    at com.google.inject.internal.InternalInjectorCreator.<init>(InternalInjectorCreator.java:61)

    at com.google.inject.Guice.createInjector(Guice.java:87)

    at com.google.inject.Guice.createInjector(Guice.java:69)

    at com.google.inject.Guice.createInjector(Guice.java:59)

    at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector(DefaultPlexusContainer.java:481)

    at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:206)

    at org.apache.maven.cli.MavenCli.container(MavenCli.java:651)

    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)

    at org.apache.maven.cli.MavenCli.main(MavenCli.java:196)

    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)

    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

    at java.base/java.lang.reflect.Method.invoke(Method.java:569)

    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)

    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)

    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)

    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)

Caused by: java.lang.ClassNotFoundException: com.google.common.collect.ImmutableSet

    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)

    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)

    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)

    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,970 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Bodapati Harish 820 Reputation points Microsoft External Staff Moderator
    2025-03-17T12:34:46.0733333+00:00

    Hello 修文 葉,

    I seem like you're running into a NoClassDefFoundError for ImmutableSet while trying to use mvn in Azure Cloud Shell. Since you mentioned that Maven was working fine before January, and now it's not, it looks like something changed on Azure's side—maybe an update to the default JDK or Maven installation.

    Here are a few things you can check:

    Check Java and Maven versions

    Run these commands to confirm what versions are currently in use:

    java -version
    
    mvn -version
    

    If Java is set to 17 but your project is Java 8, that might be the root issue.

    Manually Set Java 8 in Cloud Shell

    If your project requires Java 8, try switching Java versions:

    export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
    
    mvn clean install
    

    If you get a "Permission denied" error, Azure Cloud Shell might not allow changing the JDK. In that case, deployment from a local machine is a better option.

    Force Java 8 in Maven (pom.xml)

    If you can't change the system JDK, update your pom.xml to ensure Maven compiles using Java 8:

    <properties>
    
        <maven.compiler.source>1.8</maven.compiler.source>
    
        <maven.compiler.target>1.8</maven.compiler.target>
    
    </properties>
    

    Check for Dependency Issues

    Since the error is related to ImmutableSet, it’s likely a missing or incompatible Guava dependency. Try adding this to pom.xml:

    <dependency>
    
        <groupId>com.google.guava</groupId>
    
        <artifactId>guava</artifactId>
    
        <version>31.1-jre</version> 
    
    </dependency>
    

    Then, clean and rebuild:

    mvn clean install
    

    If you suspect an outdated version of Guava is being pulled in by another dependency, check with:

    mvn dependency:tree
    

    If multiple Guava versions show up, exclude the old one in pom.xml:

    <dependency>
    
        <groupId>com.microsoft.azure</groupId>
    
        <artifactId>azure-webapp-maven-plugin</artifactId>
    
        <version>2.5.0</version>
    
        <exclusions>
    
            <exclusion>
    
                <groupId>com.google.guava</groupId>
    
                <artifactId>guava</artifactId>
    
            </exclusion>
    
        </exclusions>
    
    </dependency>
    

    Try Deploying from a Local Machine

    If Cloud Shell is giving too much trouble, a simpler approach is to package the project locally and deploy it:

    mvn clean package
    

    Then, use Azure CLI to deploy:

    az webapp up --name <your-app-name> --resource-group <your-resource-group>
    

    Alternatively, you can set up GitHub Actions or Azure DevOps to automate deployment.

    Hope it helps!


    Please do not forget to click "Accept the answer” and Yes wherever the information provided helps you, this can be beneficial to other community members. User's image

    If you have any other questions or still running into more issues, let me know in the "comments" and I would be happy to help you.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.