How to install gradle-grails-plugin? - grails

Complete gradle nooby here.
I want to be able to execute grails build commands like "grails compile", "grails test-app" and so forth from gradle.
I found the grails-gradle-plugin from Peter Ledbrook at: https://github.com/grails/grails-gradle-plugin.
Cloning the repository I get some files and folders. In the readme file it says " include the required JARs via buildscript {} and 'apply' the plugin". The apply part sure I get but how do I add the JAR? And which jar? Do I need to use gradle on the build file in the folder of the downloaded plug-in and compile a jar? And ones I get the jar where do I place it and how do I include it in my projects build.gradle file?
I have a feeling this is going to be ridiculously easy but I just can't get it to work.

In Gradle, the jars are added to build script or to your application class path through dependencies closure e.g.
dependencies {
compile "org.grails:grails-crud:1.3.4"
compile "org.grails:grails-gorm:1.3.4"
compile "ch.qos.logback:logback-core:1.0.7"
compile "org.slf4j:slf4j-api:1.7.2"
}
compile is a name of one of the many configurations (there are also test, runtime etc.) and e.g. "org.grails:grails-crud:1.3.4" is a reference to a jar in one of the public repositories, which are also specified in your scripts in repositories closure.
You can read more about Gradle dependency management in http://gradle.org/docs/current/userguide/dependency_management.html.
For your Grails project you need to define a build.gradle file which looks similar to what is described in the README.
Though I tried today to just create a simple Grails project using that plugin and gradle init command and it didn't work. I have created an issue for that: https://github.com/grails/grails-gradle-plugin/issues/16.

Related

Jenkins Pipeline - Workflow CPS plugin JAR dependencies

I'm implementing unit tests for code used in a Jenkins Pipeline Shared Groovy Library. Specically, I need to mock the steps object available in the Jenkinsfile, which is an instance of org.jenkinsci.plugins.workflow.cps.DSL. In my Gradle build I've specified a dependency like so:
testCompile group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-cps', version: '2.30', ext: 'jar'
which is the project hosting the class above. Without specifying the ext as a JAR, Gradle retrieves the .hpi file since this is the packaging defined in the project's pom.xml; obviously I need to override this and fetch the JAR for my project. However, in doing this Gradle does not download the transitive dependencies of the workflow-cps JAR and I find myself having to populate my build.gradle with all the dependencies determined via trial and error. Is there a way to retrieve the transitive dependencies, or is this a limitation of the workflow-cps project and how it defines its pom.xml?
The CPS class you're wanting to mock won't contain methods/variables introduced by plugins or your workflow lib, so this approach probably won't be fully satisfying.
Facing the same challenge I took the pragmatic approach of making my own TestScript interface in my test sources and Mock that, and not typing the script reference in classes.
The drawbacks are not having IDE code inspection for stuff referencing the script, and having to manually add signatures to TestScript as I add tests (which is also error-prone, since I have manually ensure that those signatures match).
But it works, and avoids getting dragged into plugin dependency hell.

Exclude Grails 3 plugins before packing war file

I want to exclude some Grails 3.1.9 Plugins for deploying, because i do not need them in production. I know i can use provided instead of compile but then all dependencies of this Plugin are also excluded even if a other plugin have the same dependencies.
Example:
Plugin 1 depends on mail.jar and log.jar
Plugin 2 depends on log.jar and math.jar
snippet of build.gradle:
dependencies{
compile "com.plugin1"
compile "com.plugin2"
}
If i run gradle war, in the resulting archieve file I can find mail.jar, log.jar and math.jar. In production I do not need plugin1 so I change dependencies-block like this:
dependencies{
provided "com.plugin1"
compile "com.plugin2"
}
After gradle war it only includes math.jar.
How can i change the build.gradle file in order to pack a war- file which includes only plugin2 and all it is dependencies: log.jar and math.jar
Thanks in advance!

How to Open an Ant project (Nutch Source) at Intellij Idea?

I want to open Nutch 2.1 source file (http://www.eu.apache.org/dist/nutch/2.1/) at Intellij IDEA. Here is an explanation of how to open it at Eclipse: http://wiki.apache.org/nutch/RunNutchInEclipse
However I am not familiar with Ant (I use Maven) and when I open that source file many classes are not known by Intellij.
i.e.:
org.apache.hadoop.mapreduce.JobContext
org.apache.gora.mapreduce.GoraMapper
How can I add them to library or what should I do?
I finally figure out how to do it. Now our team can dev nutch in IntellIJ
The process we do
Get nutch source from apache.org
wget http://www.eu.apache.org/dist/nutch/2.3/apache-nutch-2.3-src.tar.gz
Import nutch source in intellij
Get Dependencies by Ant
Run ant runtime
Run ant test
Import dependencies into Intellij
File > Project Structures
Library > Ivy
Click to Plus button
Select all libraries in apache-nutch-2.3/build/lib
Now we have a project with nutch source and all dependencies
I think, you should use ant build for nutch project. Because, pom.xml is problematical for nutch. If you want to use it anyway maven, you check maven dependency in pom.xml .
I think, the problem can be solved with the following:
You create new project via idea and add nutch source. Idea is not
supported ivy ant project. You can install ivy plugin for idea, I
suppose, Idea12 does not support it.
or
You can create ant project for nutch via eclipse and then save
project. Then open the project on idea via eclipse classpath.
or
You can configure classpath. If you use ant build, you should add jars : File->ProjectStructure as follows:
Create a library
Attach Files
Then, if you use ant build, select jars from NUTCH_HOME/build/lib/* after build.
If you use maven build, select jars from ~/.m2/* (MAVEN_REPO)
Although Intellij supports running ant scripts directly through the IDE via the ant plugin, the Intellij editor will not figure out the classpath using your build.xml file by itself.This will result in the editor showing the code littered with errors.
Unfortunately the only solution I found to this is to add all the jars manually.You can get all the jars needed by building the ant project using the ant jar command.
So these are the steps you need to follow :->
1.Run ant jar command in the root of your program
2.Copy all the jars created inside the build folder(they will not be directly inside build folder.I had to go from build->ivy->lib->{project name})
3.Paste these jars to a new folder created somewhere outside the directory
4.Go to File->Project Structure->Libraries. Press the + button.
5.Select all the copied jars and press ok to any prompts which appear.
6.Press finish and wait for indexing to complete.Any dependency errors in the editor should resolve now.
Note: Since you are manually adding jars, you would need to keep them in sync if you change your build.xml file for any dependency change.
It seems that dependencies are managed using Ivy (see the ivy folder in the sources archives), so you could try to install the Ivy plugin, which would allow you to fix your classpath issues.

Referencing external dependencies in GGTS by convention

How do I reference a dependency by convention within my project build path? Allow me to elaborate...
I'm using the Groovy/Grails Tool Suite (GGTS 3.0). I'm referencing the dependency as such in my BuildConfig.groovy:
dependencies {
compile 'tgt:jaxb-utils:1.0'
}
The referenced jar file is successfully pulled down from the Artifactory repo - I can find the jar file on my local file system in the Ivy cache. When I run any grails targets (grails compile, grails run-app, grails run-tests), it works fine - meaning my code that imports the classes from the jar has no problems. When I run grails war, the referenced jar file is packed into the constructed war.
However, and here is the crux of this post - the project build path does not reference this jar file by default or convention, so my java or groovy code that imports the classes from the jar file reports a unable to resolve class ... error.
One solution is to simply add the jar file to the lib folder and update the build path accordingly, or modify the build path to reference the jar file in the Ivy cache folder. However, I'd have to do this for any/all dependencies pulled down in this way. Any jars in the lib folder will get saved to the team source code repository, and that seems like wasted space since the grails commands work fine with just the dependency reference in BuildConfig.groovy.
Am I just being too idealistic (ie - difficult) here, or is there a better way to clean up the unable to resolve class ... errors in my IDE without having to manually add the dependent jar files to my lib folder and update my build path? Ideas?
Eclipse / STS / GGTS : If you have Grails plugin installed, you can do the following :
Right click on your project -> Grails Tools -> Refresh dependencies (or shortcut "Alt+G, R")

Grails can't find classes in jars

I have an app in Grails that uses a .java to manage paypal MassPay feature. Like many .java, it needs some jars that enclose the classes that jar uses. Ok, i import that jars and the errors in the .java dissapears. But now, when I try to run the app, i receive 25 messages like this:
myapproute/grails-app/controllers/com/mycompany/widget/MassPay.java:3: package com.paypal.sdk.profiles does not exist
import com.paypal.sdk.profiles.APIProfile;
That file in the MassPay.java does not throw any error, since i imported the jar where that class is enclosed. But it doesn't allow me to run the project.
Any help? thanks.
Im using Eclipse, not NetBeans (i have read that there is a bug in Netbeans)
Adding JARs to the Eclipse project build path is not sufficient to make them visible to Grails. You need to either put them in the application's lib directory and run grails compile --refresh-dependencies or (better) if the JARs are available in a Maven-compatible repository simply declare your dependencies in BuildConfig.groovy and let Grails download the JARs itself.
Run this - it will work
grails clean

Resources