I have some dependencies from Maven Central Repository in my project. So I thought what if any dependency will be removed from Maven Central and other repositories (GitHub) and I will not be able to find this dependency somewhere and build my project?
I want to add local dependency cache to git repository of my project, so anyone could clone this repository and build my project offline. May be in Cocoapods way. How can I do this?
You already have a local maven repo, add mavenLocal() under project's repositories section. I doubt if any dependency from maven or other public hosted repos could be removed but the best way to prevent yourself from this is to host own repo - artifactory for instance. Other way is to add all the dependencies to version control system and configure gradle to read dependencies from flat file repository. Here is the whole chapter on repositories in gradle docs.
In an enterprise environment you would use a repository manager like Archiva, Artifactory or Nexus. You can configure these tools to behave as a proxy for public repositories so that all needed artifacts are cached on demand.
These tools are installed to a server so that every developer can access them and the build is set up to only have this repository so that all artifacts are cached if they aren't already available in the cache.
There's a page at Codehaus comparing the above mentioned tools.
If a repository manager is too much for you, you have to manage the local repository by yourselves.
Related
My project has more than 10+ maven repositories in the build.gradle, and the denpendencies speicified in my projoect are about 100 or more. This causes a problem. Each time I sync the gradle, it would try each maven repository for each dependency until it finds one providing that module.
The gradle docs contain the following:
A project can have multiple repositories. Gradle will look for a dependency in each repository in the order they are specified, stopping at the first repository that contains the requested module.
However, this is really time-consuming. How can I speed up this process? Can I give some hint for a denpendency using some repository, avoid trying each one blindly?
I created a Java class for helping me to use some common debuggin stuffs, for example to get the type of value, I have a method call typeOf()
Help help = new Help();
String s = "Something";
help.alert(help.typeOf(s));
above is a sample code in my class
Now every time I start a project, I need copy the class file to my project, so I want to know is there any way I can install this in my OS, then can import it to any of project whenever I needed.
In C you can move the header file to a location, then you can #include it whenever you want
If you using gradle, you can learn it from Building your own Android library but need to publish your library to jCenter or Maven Central.
Fortunately, you can make the library as a local artifact using maven plugin in the library. Read more at Deploying an Artifact to the Local Cache in Gradle
In your project, you need to add mavenLocal() to the repositories in your root build.gradle:
repositories {
mavenCentral()
mavenLocal()
}
And add the dependencies to your project build.gradle:
dependencies {
...
compile 'com.your.library:x.y.z'
...
}
But if your project is shared in your local network, you need to use Repository management like Artifactory by JFrog or Nexus Repository Manager by Sonatype.
I did a lot of research and I could't get one thing I have created my own framework and I want put in on gradle.
I do not want copy paste every time a lot of code from one project to another.
I want to do like this
compile 'xxxxx'
What should I do here to set this up?
To achieve it you have some ways:
publish your library (artifact) in central maven or jcenter.
These repo are public, it means that your artifacts will be public.
use a github repo and the jitpack plugin
These repo are public, it means that your artifacts will be public.
publish the aar in a local maven repo (local o private)
In this case the artifact can be private.
To publish a library in Central Maven or JCenter, it is very long to explain in an answer. Hovewer you can read these posts:
Publish on JCenter
Publish on Central Maven
To install a private maven , you can evaluate the nexus repository.
Check this link for more info.
I have an android library that is hosted on github and need to add it as a dependency to another project without manually cloning the repository and adding it as a module dependency. How do I go about creating my own gradle dependency with link from github? Thanks!
If you've pushed your code to GitHub then sharing your library is easy with JitPack.
Your users will just need to add the repository to their build.gradle:
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
and then your GitHub repository as dependency:
dependencies {
compile 'com.github.YourUsername:Repo:Release'
}
JitPack acts as a maven repository and can be used like Maven Central. The nice thing is that you don't have to upload your library. Behind the scenes JitPack will check out the code from GitHub and compile it. As you publish a new release on GitHub it becomes available for others to use.
There is also a guide on how to prepare an Android project.
You have to release your library to a repository which can be used by Gradle. When you want the library to be publicly available you can publish it to Maven Central. See http://central.sonatype.org/pages/gradle.html#releasing-the-deployment-to-the-central-repository for details about how to publish your library from gradle to Maven Central.
Once published in Maven Central use the normal gradle dependency declaration.
Github is not a maven repository.
if it's "free for all" license, you can clone project and post it for example in jCenter, then add it as gradle dependency.
I have a repository on Github, I would like to use my repository in Android Studio using: dependencies {compile 'com.google.code.gson: Gson: 2+'} for gradle. Does someone know how to do this?
You could use JitPack.io to expose your repository as a Maven dependency. Then including it in Android Studio is easy with gradle:
compile 'com.github.YourUsername:RepoName:ReleaseVersion'
There are more instructions on the website.
I don't know if I really got the question...I understood that you want to compile some jar files that are not local to your project and are hosted in your repository. If it is the matter, I guess you should use a custom maven repository, not a Github one. If this is the problem I can give you more details on how to create a custom maven repo.
It's like #dometheshooter said.
See:
How to publish aar file to Apache Archiva with Gradle
Guide to publish an aar to maven using gradle
How to deploy JAR to Maven remote repository
Guide to uploading artifacts to the Central Repository
Guide to deploying 3rd party JARs to remote repository