I have a small project with only one existing jar file I simply want to deploy to my local Maven repository. My build.xml:
plugins {
id 'java'
id 'maven-publish'
}
jar.enabled = false
publishing {
publications {
ModuleJar(MavenPublication) {
groupId 'de.mycompany.log4j'
artifactId "${project.name}"
version '1.2.17'
from components.java
artifact file('lib/log4j-patched.jar')
}
}
repositories {
mavenLocal()
}
}
Executing gradle clean publish
installs the jar with all other files correctly to my local Maven repository. Gradle can find it, but still attempts to compile dependent projects without that jar on the classpath.
I figured out the problem was in the file "~/.m2/repository/de/mycompany/log4j/log4j-patched/1.2.17/log4j-patched-1.2.17.module"
, where the "variants"/"files"
section seemed to be missing:
{
"formatVersion": "1.1",
"component": {
"group": "de.mycompany.log4j",
"module": "log4j-patched",
"version": "1.2.17",
"attributes": {
"org.gradle.status": "release"
}
},
"createdBy": {
"gradle": {
"version": "7.4.2"
}
},
"variants": [
{
"name": "apiElements",
"attributes": {
"org.gradle.category": "library",
"org.gradle.dependency.bundling": "external",
"org.gradle.jvm.version": 8,
"org.gradle.libraryelements": "jar",
"org.gradle.usage": "java-api"
}
},
{
"name": "runtimeElements",
"attributes": {
"org.gradle.category": "library",
"org.gradle.dependency.bundling": "external",
"org.gradle.jvm.version": 8,
"org.gradle.libraryelements": "jar",
"org.gradle.usage": "java-runtime"
}
}
]
}
Only adding
"files": [
{
"name": "log4j-patched-1.2.17.jar",
"url": "log4j-patched-1.2.17.jar",
"size": 486452,
"sha512": "a3ef13253b028eb6c1f9b6c13d4cdabacd58248656e12ed452421cf6a11403d0677b731af14cd6c02acadaf6a476b5e6385cb3ea1103c0caab99bf7daf6ad123",
"sha256": "cda50c4347907ce41d76a96fd6177af67f37d195cc72a83d35a077e887315fd2",
"sha1": "5cb110f676d6cc7f1101a0a423a6f3574c222940",
"md5": "9952949bf21e452ddd887025a6eb5aae"
}
]
to the "variants"
or simply deleting log4j-patched-1.2.17.module
does make Gradle put it on the classpath as dependency of the project. But that’s not a maintainable solution. How do I make Gradle automatically write the "files"
section in this case?