Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error finding io.netty package, but it's in pom file

I created just a barebones ‘Hello World’ project to try to resolve this. The pom file is like this:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>untitled2</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <repositories>
        <repository>
            <id>central</id>
            <name>Maven Central</name>
            <url>https://repo1.maven.org/maven2/</url>
        </repository>
    </repositories>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.netty</groupId>
                <artifactId>netty-all</artifactId>
                <version>4.1.93.Final</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

</project>

with the main class looking like this:

package org.example;

import io.netty.bootstrap.ServerBootstrap;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}

I have the import statement in there unused so it will try to build with that dependency when I run mvn clean install -U.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here is the terminal output from running that command:

PS ~\Java\untitled2> mvn clean install -U
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< org.example:untitled2 >------------------------
[INFO] Building untitled2 1.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- clean:3.2.0:clean (default-clean) @ untitled2 ---
[INFO] Deleting ~\Java\untitled2\target
[INFO]
[INFO] --- resources:3.3.0:resources (default-resources) @ untitled2 ---
[INFO] Copying 0 resource
[INFO]
[INFO] --- compiler:3.10.1:compile (default-compile) @ untitled2 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to ~\Java\untitled2\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /~/Java/untitled2/src/main/java/org/example/Main.java:[3,26] package io.netty.bootstrap does not exist
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.511 s
[INFO] Finished at: 2023-06-09T23:21:42-05:00
[INFO] ------------------------------------------------------------------------
[WARNING]
[WARNING] Plugin validation issues were detected in 2 plugin(s)
[WARNING]
[WARNING]  * org.apache.maven.plugins:maven-compiler-plugin:3.10.1
[WARNING]  * org.apache.maven.plugins:maven-resources-plugin:3.3.0
[WARNING]
[WARNING] For more or less details, use 'maven.plugin.validation' property with one of the values (case insensitive): [BRIEF, DEFAULT, VERBOSE]
[WARNING]
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project untitled2: Compilation failure
[ERROR] /~/Java/untitled2/src/main/java/org/example/Main.java:[3,26] package io.netty.bootstrap does not exist
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
PS ~\Java\untitled2>

I have a settings folder in the .m2 repo, but it’s pretty basic from what I’ve seen:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

    <localRepository>${user.home}/.m2/repository</localRepository>

    <profiles>
        <profile>
            <id>default</id>
            <repositories>
                <repository>
                    <id>central</id>
                    <name>Maven Central</name>
                    <url>https://repo1.maven.org/maven2/</url>
                </repository>
            </repositories>
        </profile>
    </profiles>


    <activeProfiles>
        <activeProfile>default</activeProfile>
    </activeProfiles>
</settings>

I’ve also tried this in the IntelliJ IDE, where I’ve tried reloading project and invalidating cache in hopes for a different outcome.

If I delete the .m2 folder, a bunch of dependencies of other projects will get downloaded okay. It seems it’s just io.netty, and I believe okhttp3 that I know of that this happens to. I triple check all of the versions, and that they are available in the maven central repository, they just don’t get downloaded to the .m2 folder / used like the other dependencies do.

>Solution :

Change your pom file to this

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.example</groupId>
   <artifactId>untitled2</artifactId>
   <version>1.0-SNAPSHOT</version>

   <properties>
      <maven.compiler.source>11</maven.compiler.source>
      <maven.compiler.target>11</maven.compiler.target>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>

   <repositories>
      <repository>
         <id>central</id>
         <name>Maven Central</name>
         <url>https://repo1.maven.org/maven2/</url>
      </repository>
   </repositories>

   <dependencies>
      <dependency>
         <groupId>io.netty</groupId>
         <artifactId>netty-all</artifactId>
         <version>4.1.93.Final</version>
      </dependency>
   </dependencies>
</project>

Declare the dependencies without the dependencyManagement tag. This should work fine. dependencyManagement is just a declaration, and it does not really add a dependency. You can read more on the difference here.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading