Gradle如何获取自定义OpenAPI生成器CLI依赖的Jar路径?
Hey there! As someone who’s navigated custom Gradle dependencies and OpenAPI Generator tweaks before, let’s break down your questions clearly.
1. How to Get the Exact Path of Your Custom Jar
There are a few reliable ways to track down that jar file:
Use a Gradle Task to Print the Path
Add this simple task to your build.gradle (or build.gradle.kts if you use Kotlin DSL) to locate and print the jar’s absolute path:
task printCustomJarPath { doLast { configurations.compileClasspath.each { file -> if (file.name.startsWith("openapi-generator-custom-cli-3.0.0")) { println "Custom Jar Path: ${file.absolutePath}" } } } }
Run it with ./gradlew printCustomJarPath (or gradlew.bat printCustomJarPath on Windows), and it’ll spit out the exact path to your console.
Navigate the Gradle Cache Manually
Gradle stores cached dependencies in a standard location:
- On Linux/macOS:
~/.gradle/caches/modules-2/files-2.1 - On Windows:
C:\Users\<YourUsername>\.gradle\caches\modules-2\files-2.1
From there, drill down into folders following this structure:org.openapitools/openapi-generator-custom-cli/3.0.0/<random-hash>/
The jar file will be inside that final folder.
Copy Path Directly from Your IDE
If you’re using an IDE like IntelliJ IDEA:
- Expand the External Libraries section in the project view
- Find
org.openapitools:openapi-generator-custom-cli:3.0.0 - Right-click the jar file, then select Copy Path > Copy Absolute Path
2. Better Best Practices for Your Workflow
Adding the jar directly to the cache works, but there are cleaner, more maintainable approaches:
Publish to Your Local Maven Repository
Instead of manually placing the jar in Gradle’s cache, use Gradle’s maven-publish plugin to publish it to your local Maven repo (~/.m2/repository). This makes your dependency declaration behave like any standard Maven/Gradle dependency.
Add this to your custom jar project’s build.gradle:
plugins { id 'maven-publish' } publishing { publications { maven(MavenPublication) { from components.java groupId = 'org.openapitools' artifactId = 'openapi-generator-custom-cli' version = '3.0.0' } } }
Then run ./gradlew publishToMavenLocal. Now you can keep your original dependency declaration (compile 'org.openapitools:openapi-generator-custom-cli:3.0.0') and Gradle will automatically pull from your local Maven repo.
Use Gradle Composite Builds (For Active Development)
If you’re still iterating on the fix for the OpenAPI Generator bug, composite builds let you directly depend on your local clone of the OpenAPI Generator project instead of building and publishing jars every time.
Add this to your main project’s settings.gradle:
includeBuild '../path/to/your/openapi-generator-custom-fork'
Gradle will treat the local project as part of your build, so any changes you make to the fix will be reflected immediately without needing to rebuild the jar.
Host on a Private Maven Repository (For Team Use)
If you’re working with a team, upload your custom jar to a private repository like Nexus or Artifactory. This lets everyone on the team pull the dependency using the same declaration, avoids manual jar sharing, and keeps versions organized.
内容的提问来源于stack exchange,提问作者Jonas Tjahjadi

