Hello everyone. I’m a beginner for gradle.
I got a problem trying to add local jar.
Basically I need to use a unmaintained project changedistiller.
However, it’s not available in mavenCentral. So I have to add the local jar by myself.
After installing changedistiller, I got the “changedistiller-0.0.1-SNAPSHOT-jar-with-dependencies.jar” which is I needed.
Begining with gradle, I’ve tried several methods.
- Using flat dir in build.gralde
I put the jar in the libs directory. But it report error with
“error: package ch.uzh.ifi.seal.changedistiller does not exist”
I believe it’s due to gradle don’t find the correct package.
- I read this thread talking about similar problem. Basically I need to give meta-info.
Following their steps. I need to create a maven local repositry.
I only have the jar file. So I copy the pom.xml in the origin changedistiller project and put it in the libs with a new name.
Now in build.gradle, I use
Still it report the same error “import ch.uzh.ifi.seal.changedistiller.ChangeDistiller;”
So I think the jar might be successfully imported. But the name might be wrong.
I try to use “/gradlew build --scan” to see what can I get.
Under the build depency, there is nothing except “com.gradle:gradle-enterprise-gradle-plugin:3.2”
I think it’s wrong but I don’t know how to correct.
Anyone could give me some suggestion?
No matter which repository type you use, you still need to declare the actual dependency. The repository is just a location to look for dependencies. It doesn’t automatically make your project depend on every single artifact in the repository.
For example, if you use the flat dir repository, you’ll have:
If you have a file named
changedistiller-0.0.1-SNAPSHOT-jar-with-dependencies.jar in the flat dir, you could add that dependency as:
implementation name: 'changedistiller', version: '0.0.1-SNAPSHOT', classifier: 'jar-with-dependencies'
You can also rename the file, if you’re not happy with the exact name, version, classifier values.
Thanks for you help. I think my problem is how to specify the correct path and name indeed.
From you advice, I’ve tried to rename this jar file in the “libs” directory with “changedistiller-0.0.1.jar” and “changedistiller.0.0.1.jar” and “changedistiller:0.0.1.jar”. As well, I add the dependency as following:
implementation name: ‘changedistiller’, version: ‘0.0.1’
All these combination report the same error:
Could not resolve all files for configuration ‘:compileClasspath’.
Could not find :changedistiller:0.0.1.
I guess there should be some naming format, but I don’t know what should I do.
Finally solve the problem by renaming.
I renamed the jar file with “changedistiller.jar”.
And in dependencies, I only put the name without version. So it looks like this
implementation name: ‘changedistiller’
Till now, it succeed to execute my program. I’m not sure whether side effect exist.