mvn install from gradle - maven

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"
}

Related

Gradle build no complete

I create the project in spring, but I have a problem with build gradle. I'm using IntelliJ and i have instal JDK Java 10 and Gradle 4.7. How to fix this?
enter image description here
Check that you have
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
in your build.gradle and re-import the project (Gradle project tool window) in IDE.

maven project as dependency in gradle project

I have a project which is using Gradle as build tool and a second subproject which is using Maven's POM. I don't have the freedom of changing build tool on the subproject.
What I want to achieve is to add my project with Maven POM as dependency on my Gradle project.
Where root (current dir) is my project with Gradle and contains the build.gradle, the Maven project is under vendor/other-proj/ with POM file just under that directory.
I have tried these variations on my build.gradle file:
1st try:
include("vendor/other-proj/")
project(':other-proj') {
projectDir = new File("vendor/other-proj/pom.xml")
}
dependencies {
compile project(':other-proj')
}
2nd try:
dependencies {
compile project('vendor/other-proj/')
}
3rd try:
dependencies {
compile project('vendor/other-proj/pom.xml')
}
4th try:
dependencies {
compile files 'vendor/other-proj/pom.xml'
}
I can't find anything related on the web, it seems most Gradle/Maven use cases are affected by publishing to Maven or generating POM, but I dont want to do any of those.
Can anybody point me to right direction?
you can "fake" including a Maven project like this:
dependencies {
compile files("vendor/other-proj/target/classes") {
builtBy "compileMavenProject"
}
}
task compileMavenProject(type: Exec) {
workingDir "vendor/other-proj/"
commandLine "/usr/bin/mvn", "clean", "compile"
}
This way Gradle will execute a Maven build (compileMavenProject) before compiling. But be aware that it is not a Gradle "project" in the traditional sense and will not show up, e.g. if you run gradle dependencies. It is just a hack to include the compiled class files in your Gradle project.
Edit:
You can use a similar technique to also include the maven dependencies:
dependencies {
compile files("vendor/other-proj/target/classes") {
builtBy "compileMavenProject"
}
compile files("vendor/other-proj/target/libs") {
builtBy "downloadMavenDependencies"
}
}
task compileMavenProject(type: Exec) {
workingDir "vendor/other-proj/"
commandLine "/usr/bin/mvn", "clean", "compile"
}
task downloadMavenDependencies(type: Exec) {
workingDir "vendor/other-proj/"
commandLine "/usr/bin/mvn", "dependency:copy-dependencies", "-DoutputDirectory=target/libs"
}
You cannot "include" a maven project in gradle settings.gradle. The simplest way would be to build the maven project and install it to your local repo using mvn install(can be default .m2, or any other custom location) and then consume it from your gradle project using groupname:modulename:version
repositories{
mavenLocal()
}
dependencies{
implementation 'vendor:otherproj:version'
}
It is possible to depend directly on the jar of the maven project using compile files but this isn't ideal because it wont fetch transitive dependencies and you'll have to add those manually yourself.

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 cannot resolve dependencies for Sonar-Runner

I am trying to set up the Sonar-Runner with my existing gradle project. I am using Sonar-Runner 2.4 Gradle 2.2.1 and our Sonar server is 4.3.1. When I run gradle sonarRunner I get the following error:
Could not resolve all dependencies for configuration ':sonarRunner'.
Cannot resolve external dependency org.codehaus.sonar.runner:sonar-runner-dist:2.4 because no repositories are defined.
I do have the artifact "org.codehaus.sonar.runner:sonar-runner-dist:2.4" in my nexus server that is set up in my build.gradle file. Does anyone have any intuition about this error? I have googled it extensively and been stuck on this for a couple of hours now.
My build.gradle for the sonar runner is very simple:
apply plugin: 'sonar-runner"
sonarRunner{
toolVersion = '2.4'
sonarProperties{
property "sonar.host.url", "$sonarHost"
}
}
It seems no repository is declared for the project you want to use with the sonar-runner plugin.
You might have configured repositories for buildscript or for other projects only (in your multiproject build?)
To resolve the sonar-runner you need to configure a repository where it could be resolved from. You might have a coorporate repository in your company or you could use public ones like mavencentral or bintray. to declare for example the jcenter repository to resolve the sonar-runner. just add the following to your build script:
repositories {
jcenter()
}

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

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.

Resources