How can integrate gradle project wih Eclipse (maven) based instrumentation tests - maven

I have an android project in AndroidStudio, but we must outsource the Instrumentation test to Eclipse (simple Java projet which builded by maven). I don't would like to tell the whole development and QA story about why, I'm just kindly asking can anyone tell me, who can I integrate an maven independed instrumentation test project with my Android Studio based project ?

In gradle you can make a .jar from your project by building it, and then you can publish the .jar artifact to any maven repo (check this if your are not familiar with artifact publishing).
Something like this:
artifacts {
archives file("path/to/your/project_output.jar")
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://${System.env.HOME}/.m2/repository/")
pom.groupId = 'com.yourcompany'
pom.artifactId = 'yourartifactid'
pom.version = '0.1.0'
}
}
}
This will publish your project's compiled jar files to your local maven repository.
Look for the .jar file in the build/intermediates/... folder (classes.jar its default name I think)
Also, you should publish your .apk file too if your test project needs it.

Related

How to import a maven module to an Android Studio project

I would like to include retrofit as a module in my Android Studio project. The problem is that retrofit is a maven project and so Android Studio won't let me import it. Is there a way around this?
A similar question has been asked before, but it received no answers.
Use a custom group and/or artifact in the POM of your clone, so your clone cannot be confused with the original.
Build and install your clone of Retrofit using Maven as usual: mvn install. (Using the command line or an IDE other than Android Studio.) You have to build your Retrofit clone manually after each change you make to it, for Gradle to see the changes.
Add the local Maven repository to your Gradle script. See https://docs.gradle.org/2.5/dsl/org.gradle.api.artifacts.dsl.RepositoryHandler.html#org.gradle.api.artifacts.dsl.RepositoryHandler:mavenLocal():
repositories {
mavenLocal()
}
Add the GAV of your clone as a dependency to your Gradle script:
dependencies {
compile 'com.yourgroup:retrofit:1.9.0-custom'
}
Go to your project then goto the app. You will see a build.gradle file under app (DO NOT use the gradle under gradle folder but the ine under app folder). Add this line.
dependencies {
....
compile 'com.squareup.retrofit:retrofit:1.9.0'
...
}
Then, make sure that you define the repository details in directory and add the url.
repositories {
flatDir {
dirs 'libs'
}
maven { url 'http://download.crashlytics.com/maven' }
}``
See Migrating from Maven to Gradle. Just execute gradle init.
Just add it to the dependencies { } block of your application's build.gradle file.
dependencies {
compile 'com.squareup.retrofit:retrofit:1.9.0'
}
In android studio simply go to project structure -> module you want to add retrofit -> dependencies tab -> plus(add) -> library dependency and then type retrofit in text box and select com.squareup.retrofit:retrofit and add to your dependencies
another soluation , just download latest jar file from https://github.com/google/retrofit then
goto new module ->create module of jar->select the path of that jar file->then on your project module gradle dependency add(implementation(':name retrofit module').

gradle with maven submodule

There is any way to build gradle project with maven submodule ? I created a project in gradle but at now I must add module (that module used a maven) I don't have any idea how to used this. There is any good way?
I will be very gratefull for any suggestions.
Either convert the Maven project to Gradle (gradle init is a good start) and turn the Gradle build into a multi-project build, or publish the Maven build's artifact to the local or a remote Maven repository, and configure the Gradle build to consume it from there (or the other way around).
Create a build.gradle(.kts) that wraps the Maven project in its root directory:
val build = task<Exec>("build") {
commandLine("mvn", "package")
}
val default by configurations.creating {
isCanBeConsumed = true
isCanBeResolved = false
}
artifacts {
add(default.name, File("$projectDir/target/<name of the jar>.jar")) {
builtBy(build)
}
}
You can then depend on it like this:
implementation(project(":<path to the module>", "default"))

mvn install from gradle

I have a created a gradle project and a different project was created in Maven.
The jar from the maven project is a dependency to the gradle project.
Is it possible to run the mvn install for the maven project and add the jar to the gradle project?
Thanks & Regards
Mukund
All that's needed on the Gradle side is:
repositories {
mavenLocal()
}
dependencies {
compile "some.group:someArtifact:1.0"
}

Gradle script to copy maven artifact from local folder to another folder

In my project i want to copy certain artifact (war file) from maven repo to local folder in order to deploy. I tried using configurations object but i couldn't give specific groupid, artifact id, and version in that way
repositories {
mavenCentral() // or some other repo
}
configurations {
deploy
}
dependencies {
deploy "someGroup:someArtifact:someVersion"
}
task copyDeploy(type: Copy) {
from configurations.deploy
into "deploy"
}
You can find all of this and more in the Gradle User Guide (e.g. under "Working with dependencies") and the many samples in the full Gradle distribution.

Getting Gradle to publish a source Jar instead of a standard compiled Jar

I am slowly moving two projects over to Gradle. Project A produces a jar file that is used by Project B.
Project A is a GWT component and Project B is a GWT application.
How do I get Gradle to generate a Jar that contains the Java source code of Project A rather than the compiled classes?
I have tried adding the following to the build.gradle file, but this generates a second Jar file containing the source - I want the main artefact to contain the source, so that it is published to my local Maven repository when I run the install task.
task sourceJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourceJar
}
Is there a way to override the standard Jar creation task?
You can define your own 'myArtifacts' configuration and publish that instead. Note that since the install task is of type Upload, you should be able to change the default artifacts configuration from archives to sourceArchives:
configurations{
sourceArchives
}
artifacts{
sourceArchives sourceJar
}
install.configuration = configurations.sourceArchives
Hopefully, install should now just publish members of sourceArchives configuration.

Resources