Consider how to set a Maven artifact in Gradle as a dependency, although the source is public, but the artifact is not registered in the public repository.
--Example) Azure Notification Hub: Azure / azure-notificationhubs-java-backend
com.windowsazureNotificationHubs0.0.4--How to use --Plain jar with no external dependencies-> Method 1 --Maven jar without external dependency-> Method 2/3 --Maven jar with external dependency-> Method 3
--Project structure
- gradle-project
  - build.gradle
  - lib
    - NotificationHubs-0.0.4.jar
build.gradle
dependencies {
    compile files ('lib/NotificationHubs-0.0.4.jar') //Specify by file path
}
--Limited to jar files that do not refer to external modules.
--If the jar file is a Maven artifact, the dependencies used by the module specified in files will not be resolved. Run-time error at runtime.
--If you can refer to the source file of the jar, you can make the target Maven artifact a fat jar with the ʻassembyorshade` Maven plugin.
--Project structure --Same as method 1
build.gradle
repositories {
    flatDir {
        dirs "lib" //You can refer to the jar placed in this folder in the usual dependencies notation.
    }
}
dependencies {
    compile('com.windowsazure:NotificationHubs:0.0.4') // groupId/artifactId/version
}
--The external dependency of NotificationHubs has not been resolved. Even if it can be compiled, the class cannot be found at runtime and an error occurs.

--Similar to method 1, if the referenced module has additional external dependencies, the dependencies will not be resolved.
--Caution when using in multi-project
--If you define a flatDir that specifies its own lib in the referenced subproject, the referenced subproject will reference its own lib and will fail to resolve dependencies.
- GRADLE-1940 Unresolved dependencies when project A depends on project B and A does not have a reference to the repository used by B
--Place lib in the root project and make sure that the subproject refers to lib in the root project.
build.gradle
subprojects {
    repositories {
        flatDir {
            dirs "${rootProject.projectDir}/lib"
        }
    }
}
--Project structure --Use the folder structure of Maven's local repository
- gradle-project
  - build.gradle
  - lib
    - com
      - windowsazure
        -  NotificationHubs
          -  0.0.4
            - NotificationHubs-0.0.4.jar
            - NotificationHubs-0.0.4.pom
build.gradle
repositories {
    maven {
        url "lib"
    }
}
dependencies {
    compile('com.windowsazure:NotificationHubs:0.0.4') // groupId/artifactId/version
}
--The external dependency of Notification Hubs has been resolved.

--Note that there is the same problem as method 2 in the multi-project configuration.
Recommended Posts