Search code examples
javamavenmaven-3mvn-repo

Can't impot ntfy.java package from GitHub Maven repository


I'm trying to use com.github.maheshbabu11.ntfy.java in my project, but Maven can't find it:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile): Compilation failure: Package ntfyJava is not available.

However, when I downloaded the Java source files, my code was compiled and executed perfectly fine.

My import statements:

import ntfyJava.NtfyClient;
import ntfyJava.core.model.*;
import ntfyJava.core.publish.PubClient;

My pom.xml:

<?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>page.codeberg.pixelcode.group</groupId>
    <artifactId>page.codeberg.pixelcode.artifact</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>22</maven.compiler.source>
        <maven.compiler.target>22</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.17.0-rc1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jdk8 -->
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jdk8</artifactId>
            <version>2.17.1</version>
        </dependency>
        <dependency>
            <groupId>com.github.maheshbabu11</groupId>
            <artifactId>ntfy.java</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>central</id>
            <url>https://repo.maven.apache.org/maven2/</url>
        </repository>
         <repository>
          <id>github</id>
          <url>https://maven.pkg.github.com/MaheshBabu11/ntfy-java</url>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
    </repositories>

</project>

I configured my ~/.m2/settings.xml according to GitHub's Maven docs:

<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">

  <activeProfiles>
    <activeProfile>github</activeProfile>
  </activeProfiles>

  <profiles>
    <profile>
      <id>github</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>https://repo1.maven.org/maven2</url>
        </repository>
        <repository>
          <id>github</id>
          <url>https://maven.pkg.github.com/MaheshBabu11/ntfy-java</url>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
    </profile>
  </profiles>

  <servers>
    <server>
      <id>github</id>
      <username>realpixelcode</username>
      <password>github_pat_CMU...OJ8</password>
    </server>
  </servers>
</settings>

My module-info.java:

module page.codeberg.pixelcode.Group {
    requires ntfy.java;
}

How to import ntfyJava correctly from GitHub?

Thank you!


Solution

  • Fixed in the upstream repo:

    This issue was my bad, the folder structure has to be src/main/java/<package-name> for the package to build properly. have fixed that issue and you should be able to download the jar and get it working.

    – Mahesh Babu
    https://github.com/MaheshBabu11/ntfy-java/issues/7#issuecomment-2147481368