Can anyone explain clairly what is Maven repository in Android Studio ? I try to understand it but I don't find better explainations.
Last time I needed to add some dependencies in my project and they didn't work untill I added a link to Maven and Jcenter in my build.gradle file.
It worked parfectly but my question is just to know What is exactly maven and Jcenter in Android Studio ?
Thanks in advance with your answers.
A maven repository is a "repo", public or private, to store libraries, plugins and in general artifacts.
It is not related to Android Studio or another IDE.
JCenter is one of the maven repo.
JCenter is the place to find and share popular Apache Maven packages for use by Maven, Gradle, Ivy, SBT, etc.
Other common repo used in Android are:
Maven Central
Google maven repo
In a gradle script you can find them in the repositories block:
/**
* The repositories block configures the repositories Gradle uses to
* search or download the dependencies. Gradle pre-configures support for remote
* repositories such as JCenter, Maven Central, and Ivy. You can also use local
* repositories or define your own remote repositories. The code below defines
* JCenter as the repository Gradle should use to look for its dependencies.
*
* New projects created using Android Studio 3.0 and higher also include
* Google's Maven repository.
*/
repositories {
google()
jcenter()
}
Im not Java guy but from fast lookup in google:
Maven is build and dependency management tool (helps in building project and downloading dependencies).
Jcenter looks like repository of available libraries (is source for all dependencies downloaded by maven processes).
Related
I created a plugin for gradle with java.I want to test it.
so, I created a another gradle project add I added my plugin as a module.
Now , How can I apply my module as a plugin in build.gradle file ?
My project structure
My plugin
version '1.0.0'
id = 'com.hello.first.plugin'
implementationClass = 'com.hello.first.plugin'
Here I saw for applying jar as a plugin in gradle : ANSWER.
How can I add module as a plugin in build.gradle ?
You need to make it a standalone project and publish it, at least to mavenLocal().
Then just add mavenLocal() into buildscript.dependencies and it should resolve.
A local flatDir repository should work, too.
I am trying to use the grgit plugin from within my gradle script. I have a file that is modified by our CI server during build and I want this to be committed to out git repo as part of the build process.
I have a local Nexus repo which has a proxy to maven central. How do i get access to the gradle plugin via my Nexus repo? Currently, I have:
buildscript {
repositories {
maven {
url "http://my-nexus:6666/nexus/content/groups/public/"
}
}
dependencies {
classpath "org.ajoberstar:grgit:1.7.2"
}
}
apply plugin: "org.ajoberstar.grgit"
This downloads the dependency from Nexus, but results in > Plugin with id 'org.ajoberstar.grgit' not found. when doing a gradle build.
I have read the documentation regarding custom plugin repositories but prefer the old method rather than the DSL method because I have hundreds of projects and don't want to define the repository in every settings.gradle file since at the moment, pluginRepositories can only be specified in the settings.gradle file.
How can I get the apply plugin method to work?
That's because the version of the Grgit library you use does not have the Gradle plugin included. Only newer versions, that are not in maven central nor jcenter (only in Gradle plugins repository).
You have two ways to fix it
a) Change the library:
buildscript {
repositories {
maven {
url "http://my-nexus:6666/nexus/content/groups/public/"
}
}
dependencies {
classpath "org.ajoberstar:gradle-git:1.7.2"
}
}
apply plugin: "org.ajoberstar.grgit"
b) Mirror the gradle-plugins repository in your local Nexus repo from
https://plugins.gradle.org/m2/ and version of 2.1.1 grgit
There is a library that I would like to use for my Android App: ez Vcard. However this library uses Maven, which I'm not familiar with. I checked online and my Import Project objection doesn't offer pom.xml soo, how can I add the dependency
<dependency>
<groupId>com.googlecode.ez-vcard</groupId>
<artifactId>ez-vcard</artifactId>
<version>0.9.9</version>
</dependency>
into my project and specifically where?
You don't need a maven project, you can use maven dependencies in gradle projects, you'll just have to use a gradle format of the dependency.
This library appears to be hosted on maven central, so you have to link to this repository host in your global build.gradle:
allprojects {
repositories {
mavenCentral()
}
}
To import this dependency into your project, in your module-local build.gradle file input the following lines:
dependencies {
compile 'com.googlecode.ez-vcard:ez-vcard:0.9.9'
// all the other dependencies...
}
You can actually see here all the different dependency formats (under 'Dependency Information'), from maven to gradle, ivy, sbt and so on, they are all compatible with the repository.
This is how import dependencies in Android Studio. In this case okhttp:
dependencies {
compile 'com.squareup.okhttp:okhttp:2.5.0'
}
I would like to import a dependency created by myself. For example:
dependencies {
compile 'my_library:1.0.0'
}
At this point if I learn how to create a dependency and import in Android Studio project would be enough.
But I would like host my library on a git(github) repository if possible. This would be awesome.
To achieve it you have some ways:
publish your library (artifact) in central maven or jcenter.
use a github repo and the jitpack plugin
publish the aar in a local maven repo (local o private)
The point 2. is very simple. Just push your codein github and modify the gradle script in the project where you want to use it.
Just add this repo tp your build.gradle
repositories {
// ...
maven { url "https://jitpack.io" }
}
and the dependency:
dependencies {
compile 'com.github.User:Repo:Tag'
}
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
i had been using eclipse .it was fine with m2 plugin.now i switched to android studio.i dont know how to convert my project to maven project.Any help would be appreciated?
P.s I installed maven in my windows 7. in build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.0'
}
}
mavenCentral() is the central repository shorthand, it's like this tag in the pom.xml.
build.gradle is a Gradle build system build file, to convert to Maven build system you need a pom.xml.
I suggest you import your existing project (which has the pom.xml) view File > Import Project... and select Maven during the import.
Google's suggested way of building Android apps is with Android Studio, which tightly integrates with Gradle and that's the preferred and most advanced way of assembling apks for apps.
Referencing libs
Gradle has what Maven has and more.
<project>
<dependencies>
<dependency>
<groupId>com.github.bumptech.glide</groupId>
<artifactId>glide</artifactId>
<version>3.3.1</version>
</dependency>
</dependencies>
</project>
is the same as (be careful this is not the same as buildscript { dependencies { ... } })
dependencies {
compile 'com.github.bumptech.glide:glide:3.3.1'
}
See the Dependency Information in the Maven Central search for this lib: http://search.maven.org/#artifactdetails%7Ccom.github.bumptech.glide%7Cglide%7C3.3.1%7Cjar