Grails Download zip file as dependency - maven

I have a standalone custom code packed as a zip file(custom-1.0.zip) using maven-shade-plugin –uploaded to my company's artifactory
<dependency>
<groupId>com/mypackage/domain</groupId>
<artifactId>custom</artifactId>
<version>1.0</version>
<type>zip</type>
</dependency>
I want to use this zip file in my Grails 2.3.5 project which is configured to use maven for resolving dependencies. I believe I need to do following:
Download the zip file from artifactory to local maven repository
Copy the zip file from local maven repository to web-app/resources folder of my project
I added following to Build.groovy to download the zip file:
grails.project.dependency.resolver = "maven"
dependencies {
compile ("com.mypackage.domain:custom:1.0")
}
…
..
plugins {
compile ("com.mypackage.domain:custom:1.0")
}
Above code downloads the jar, pom and zip file to my local maven repository and then fails
Loading Grails 2.3.5
|Configuring classpath
|Downloading: com.mypackage.domain/custom/1.0/custom-1.0.pom
|Downloading: com.mypackage.domain/custom/1.0/custom-1.0.zip
|Downloading: com.mypackage.domain/custom/1.0/custom-1.0.jar
.
|Environment set to development
.................................
|Packaging Grails application
Error |
Zip C:\Users\userid\.m2\repository\com\mypackage\domain\custom\1.0\custom-
1.0.zip is not a valid plugin
Does anyone has a working example for downloading zip using Grails 2.3.5 and copying to desired folder?

You do not need the following unless the custom artifact is built as a plugin. You can remove
plugins {
compile ("com.mypackage.domain:custom:1.0")
}
and edit the dependencies to include the type:
dependencies {
compile ("com.mypackage.domain:custom:1.0:zip")
}
then compile your project.

Related

Where does gradle stores the jars of external plugins?

I am using an external gradle plugin called jsonschema2pojo. For that I added the following code inside build.gradle file and I could successfully use that plugin. But I cannot locate the jar that must be downloaded and stored somewhere.
Where do I find the jar that is downloaded for external plugin?
I looked inside ~/.gradle/caches/ folder. For me the caches folder contains the following subfolders:
2.11, 3.3, jars-1, modules-2, artifacts-24, jars-2.
In this project I am using gradle wrapper (with gradle version 2.11) to build the project. So I looked inside ~/.gradle/caches/2.11 folder which contains the following subdirectories:
plugin-resolution, scripts, workerMain.
I was expecting a jar starts with jsonschema2pojo somewhere here, but could not locate one.
buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath 'org.jsonschema2pojo:jsonschema2pojo-gradle-plugin:0.4.29'
}
}
apply plugin: 'jsonschema2pojo'
You will find the plugin .jar file inside the ~/.gradle/caches/modules-2/files-2.1/ folder.

How can i package jar so that dependent spring jars wont include in my final jar instead refer them to a maven repository

Trying to build a jar with Gradle which has some spring dependencies and put in a nexus repository. and My build.gradle looks like below
dependencies {
compile group: 'org.springframework', name: 'spring-jdbc', version: '3.1.0.RELEASE'
compile("org.springframework.cloud:spring-cloud-spring-service-connector:1.2.2.RELEASE")
compile("org.springframework.cloud:spring-cloud-cloudfoundry-connector:1.2.2.RELEASE")
}
When i bundle my jar using this it just includes these jars in my final jar.
jar {
baseName = 'npswo-framework'
version = '0.1.0'
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
I am looking for something where my final jar should have some reference to these jars may be through META-INF and download them when someone download my jar.
Currently if someone download or refer my jar in nexus it includes spring jar folders under my jar and they are being duplicated if the project already has spring reference
Maven publish plugin in gradle resolved the issue , We can follow any example of creating publish plugin in gradle

Gradle does not add transitive dependencies to war's WEB-INF/lib folder

I have a web project that produces a war. The war adds a jar (another project of mine posted on an external repo) as compile dependency. This jar has its own compile dependency, which is listed in the jar's pom file, as well as in the project's build script (this is a Gradle project). I would like to add the jar, as well as all of its own dependencies to my war's WEB-INF/lib folder. However, when I build the web project with Gradle, only the direct dependency is added, not the transitive ones.
Here is my web project's build script:
apply plugin: 'war'
repositories {
maven {url "http://repo-url"}
}
configurations.all {
resolutionStrategy {
cacheChangingModulesFor 0, 'seconds'
}
}
dependencies {
compile('com.company.group:artifact-name:1.0.0-SNAPSHOT') {
changing = true
transitive = true
}
}
The com.company.group:artifact-name:1.0.0-SNAPSHOT does have its own POM, which lists the following dependency:
<dependency>
<groupId>us.codecraft</groupId>
<artifactId>xsoup</artifactId>
<version>0.2.0</version>
<scope>compile</scope>
</dependency>
Also, I've set cacheChangingModulesFor to 0 seconds, so that, effectively, the latest version of the SNAPSHOT jar is used every time.
The issue I am having is the 'us.codecraft:xsoup:0.2.0' artifact does not get included in the war, even though it is a transitive dependency of the war.
Any thoughts? Ask for more details, if anything is unclear.
Ok, it turns out the problem lay in how Gradle resolved the snapshot artifact that my web project depended on. For some unknown reason, during some builds Gradle would not download the most up-to-date jar, which prevented it from downloading the transitive dependency that I needed in my war, because it was not a dependency of this older jar. Deleting the older snapshot jar from my repo fixed the issue.

Importing Maven dependency

I'm trying to include ViewPagerIndicator into my project and I'd rather use the Maven dependency rather than importing the android library project. There's some code posted for maven
<dependency>
<groupId>com.viewpagerindicator</groupId>
<artifactId>library</artifactId>
<version>2.4.1</version>
<type>apklib</type>
</dependency>
and inside the sample project, that code is in a pom.xml file, but I don't have that file. Can I translate the above code into my build.gradle file? Or can I just create a pom.xml file and put it in my project?
You should ask the author JakeWharton to make an aar available on Maven Central. (vote here: https://github.com/JakeWharton/Android-ViewPagerIndicator/pull/229). Until then there is a temporary solution to use maven repo from community.
repositories {
maven {
url 'https://github.com/Goddchen/mvn-repo/raw/master/'
}
mavenCentral()
}
dependencies {
compile 'com.actionbarsherlock:viewpagerindicator:2.4.1'
}
https://github.com/Goddchen/mvn-repo
You will find the file in Maven Central which means simple run the build and the file will be downloaded. This is also true for gradle where it looks like this:
'com.viewpagerindicator', name: 'library', version: '2.4.1', ext: 'apklib'

Gradle Dependency loading from maven

I am new to gradle.
I have seen some examples about java dependency like the following example but my project will be simply a zip file.
I just want to download the zip file.
apply plugin: 'java'
dependencies {
compile 'commons-lang:commons-lang:2.6'
}
In the above example, it will automatically download the jar file. But it doesn't download my zip file if my maven repositories contains zip that mentioned in the pom.xml about that package.
Questions:
What is the flow when depend on a maven repository? It will first read the pom.xml and then download the zip file?
How to dynamically load the dependency? e.g 'commons-lang:commons-lang:2.6' will have dependency of 'commons-lang:en:1.0" in the pom.xml. How to make it automatically load and loop the dependency list?
Thanks all
I have tried the follwoing script but it gives me error on compile but I have apply the java plugin
My gradle file
apply plugin: 'java'
repositories {
mavenLocal()
maven {
url "http://nexus.com/myrepo/"
}
}
dependencies {
compile 'com.a.b:projectA:2.0#zip'
}
I can run without problem that files downloaded are inside .m2
Question about the transitive dependency
I have the pom.xml like this. But it is unable to load the dependency one. It will directly go to the new pom.xml first or download zip directly if i mention sth like this?
<dependencies>
<dependency>
<groupId>com.a.b.c</groupId>
<artifactId>base</artifactId>
<version>1.2</version>
<type>zip</type>
</dependency>
</dependencies>
When declaring a dependency and a maven repository, this maven repository will be used to resolve the artifact. this means that usually first the metadata is read and then the artifact will be downloaded. If no repository is declared the resolution will fail early.
Having a dependency notation like yours:
dependencies {
compile 'commons-lang:commons-lang:2.6'
}
gradle resolves the default artifact of that dependency. If you want to resolve additional declared zip files from maven central, you have to use this notation
repositories{
mavenCentral()
}
dependencies {
compile 'commons-lang:commons-lang:2.6#zip'
}
As a default, the a dependency is transitive. This means, that if e.g 'commons-lang:commons-lang:2.6' has a dependency on 'commons-lang:en:1.0" in its pom.xml the commons-lang library (and again its transitive dependencies if any) is also resolved.
cheers,
René

Resources