Where does gradle stores the jars of external plugins? - gradle

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.

Related

Generate jar with Bundle-SymbolicName value in a Liferay module

By default, Blade generates the jar file of a module including the module version.
Searching information about how to remove the version from de filename, I was success change the jar's name with only the project name using this code in the workspace build.gradle file:
allprojects {
apply plugin: 'java'
jar.archiveFileName = "${project.name}.jar"
}
Now, I'm trying to use the symbolic name of the module (the value from the Bundle-SymbolicName attribute in bnd.bnd file) to generate the jar, but I can't find the way to get it from the build.gradle file.
Is there way to do it?
Finally, the solution was quite simple. When using the deploy task from the Liferay plugin in IntelliJ, it generates the .jar file with the version in the build/libs directory of the module, but deploys it to the server (directory bundles/osgi/modules) without the version.

How to refer resource files from dependent jar in gradle task?

I want to use resource file from dependent jar to generate code/POJO. Maven has maven-remote-resources-plugin. I didn't find any equivalent gradle plugin. Also not sure if gradle has any default task for the same.
I use this way to use my custom lib with Gradle:
Copy your JAR file to your module ‘libs’ folder. If you don’t have ‘libs’ folder then create one.
Add the library to your ‘module’ Gradle dependencies
dependencies:
dependencies {
compile files('libs/your-library-file-name.jar')
}

Gradle include jar produced by another project in war

Currently I have two projects with gradle build.gradle. The first is going to create a fat jar file, which I would like to include in a war file. I thought compiling it would be enough, but it doesn't seem to be ending up in the /lib directory of my war file. Anyone have thoughts I am quite new to gradle.
dependencies {
compile project(':JarProject')
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
providedCompile 'org.apache.tomcat:tomcat-jsp-api:7.0.55'
}
war {
archiveName 'WarProject.war'
from 'JarProject/build/libs'
webXml = file('src/web.xml')
}
Does the second project war need to be in providedRuntime? Or should I publish the jar from the other project in the local maven repo and include it that way?
The War task essentially behaves like a CopyTask with regards to stuff it packs in the war, so the documentation on working with files is useful. In essence, I think you need something like (untested):
from fileTree('JarProject/build/libs') {
into("lib")
}
That being said, using mavenLocal() and publishing there also works, but it can lead to unexpected results when the war includes some old version from local, picking up the jar explicitly from the file system like above is better.
I think the elegant solution would be to use multi project builds and project level dependencies. You would have the two builds as separate projects of the same Gradle build and add the "jar project" as a regular compile dependency.
How have you declared the dependency? I assume you have a multi-project build with subprojects A and B, both using the War plugin. I made an experiment using Gradle 2.4 and if I declare B/build.gradle like this:
apply plugin: 'war'
dependencies {
compile project(':A')
}
then B.war contains WEB-INF/lib/A.jar. If you correctly follow conventions of Gradle War plugin (place web resources in A/src/main/webapp/ and code-related resources in A/src/main/resources/), then A.jar should contain what you want.
see this

Gradle: Applying from external gradle file which is downloaded as artifact

I have a test lrg.gradle file which is supposed to do the following
lrg.gradle
dependencies {
classpath group: '<group path>', name: '<gradle file>', version: "${Version}",
}
apply from <above downloaded gradle file>
I am looking on how to apply from the above downloaded gradle file. Where will the gradle file downloaded and which variable i need to refer to access the cached location. Assuming it is stored in GRADLE_USER_HOME/caches.
Basically we want to have this in all Test LRG files so that all common tasks and dependencies can be applied from common artifact gradle file. So that they can be used like dependent tasks for the tasks defined.
You can apply from a URL like so:
apply from: "http://artifactory.url/maven/repo/$group/$name/$version/common.gradle"
That should allow you to avoid declaring a dependency on the common.gradle file.

Load gradle plugin from sibling folder

I've started to create a Gradle plugin. The build is finishing and producing a valid plugin jar (I think), but the implementation is skeletal. I have a couple of unit tests, but I want to have a very simple way to "system test" the plugin.
The original plugin is in my Eclipse workspace. I want to create a second Eclipse standalone project with a build.gradle that references the jar produced by the other project, just using a relative path to the jar in the other project's "build" folder.
My first stab at this is:
buildscript {
repositories {
jcenter()
mavenCentral()
flatDir {
dirs "../GradleYangPlugin/build/libs"
}
}
dependencies {
classpath files("GradleYangPlugin-1.0.0-SNAPSHOT.jar")
}
}
apply plugin:"com.att.opnfv.yang.gradle"
I then just tried "gradle tasks" to see what it said. It fails with "Plugin with id 'com.att.opnfv.yang.gradle' not found."
You might ask whether I constructed the plugin jar correctly. That's a valid question, but I can show that's not even relevant yet. I ran a File IO monitor (SysInternals ProcessMonitor) while I ran the build, looking for any occurrences of "GradleYangPlugin-1.0.0-SNAPSHOT.jar". The only place it looked for it was in the current directory (the root directory of the second project). This shows that the syntax I used for my "flatDir" element isn't groked by Gradle, and it's also not complaining about it. It just ignores it, seemingly.

Resources