I have a plugin project which I created as grails create-plugin myPlugin. I also created a 'normal' grails project as grails create-app myPluginDemo. I'm trying to install myPlugin plugin in myPluginDemo but don't understand how to use grails.plugin.location.
Where do I put grails.plugin.location inside BuildConfig.groovy? Inside plugins section? Inside repositories section?
What should I append to grails.plugin.location? Should it be grails.plugin.location.myPlugin? Or grails.plugin.location.grails-my-plugin? Something else?
grails.plugin.location is not a dependency resolution, so it goes outside grails.project.dependency.resolution.
It should be like below, if both myPluginDemo and myPlugin are in the same directory. Moreover, this will not install the plugin into the app, but the application will refer to the file system for the plugin which is convenient in development mode. In order to use the packaged plugin it has to be referred in plugins inside grails.project.dependency.resolution
grails.plugin.location.myPlugin = "../myPlugin"
grails.project.dependency.resolution = {
repositories {
}
dependencies {
}
plugins {
}
}
Related
I am trying to upgrade my application from Grails 2.4.4 to Grails 3.2.0. I am having problems installing plugins used in previous version. Following Questions did gave me some clarification :
1) First one
2) Second one
Now I have few plugins like tomcat, jquery,etc which are not available at https://bintray.com/grails/plugins as described in First one question.
So can you tell me how do I add plugins which are not in this directory on plugins at bintray.
There is some problem as well I am using database-migration plugin. There is listing available at bintray and says to use it as
compile 'org.grails.plugins:database-migration:3.0.0'
as I added same in build.gradle file in my project under dependencies section. Project gets compiled successfully but does not run. Shows long exception but starting is as follows :
org.gradle.api.tasks.TaskExecutionException: Execution failed for task
':bootRun'.
Please help to resolve this errors while installing plugin in Grails 3.2.0
You need an extra configuration for that plugin as its doc says.
Add in build.gradle
buildscript {
dependencies {
...
classpath 'org.grails.plugins:database-migration:3.0.0'
}
}
dependencies {
...
compile 'org.grails.plugins:database-migration:3.0.0'
}
It is also recommended to add a direct dependency to liquibase because Spring Boot overrides the one provided by this plugin
dependencies {
...
compile 'org.liquibase:liquibase-core:3.5.3'
}
You should also tell Gradle about the migrations folder
sourceSets {
main {
resources {
srcDir 'grails-app/migrations'
}
}
}
Maybe plugins are no longer necessary and don't have direct replacements. The tomcat plugin is not needed because Grails 3 is built on Spring Boot and the dependency:
compile "org.springframework.boot:spring-boot-starter-tomcat"
Provides tomcat already. The jQuery plugin is not needed either because you can simply declare a dependency on the jquery.js file directly using asset pipeline which is just as simple. See How to Use jQuery in Grails 3.0
I have a project where I want to include the console plugin for certain environments but not for others - it should go in the (custom) deployTest environment, but not for Production.
If I build the app using grails, I have a BuildConfig.groovy that looks like:
grails.project.dependency.resolution = {
/// some stuff
plugins {
/// more dependencies
if (Environment.current != Environment.PRODUCTION){
compile ":console:1.5.1"
}
}
}
Dependency resolution for Grails when using Gradle to build it is based on the build.gradle file, not the BuildConfig.groovy.
How do I achieve this please?
It seems more to me like you want to INCLUDE a dependency based upon the environment. However, the approach will be the same either way. In your build.gradle file you have a 'dependencies' section. Since this is Groovy, it is code. The -PgrailsEnv value is used by gradle to specify the environment. Just use that:
dependencies {
// if no property, then gradle will be default to prod. So test
// for that or having it explicitly provided
if (!project.hasProperty('grailsEnv') || project.grailsEnv.equals('prod')) {
compile ':console:1.5.1'
}
}
I have the following setup within my project...
A multi project gradle build for a SOA style project, wired together using rabbitmq and spring integration.
Contains a number of grails projects as well as plain java / groovy projects to represent the services.
Alongside each of the service projects are a project (jar) containing all of the public interfaces (and messages) for the service that can be proxied using spring integration.
The projects are related to each other using gradle dependencies and then I generate IntelliJ projects files using the gradle idea plugin.
What I want to do is:
Include the interfaces jar in the grails project so that I can use spring integration there to proxy my calls into the services via rabbitmq.
When I run the grails app have this intefaces jar built and included within grails.
When I run the grails app from IntelliJ have it compile the latest version of the interfaces and include them in the grails project.
When I build the entire project from gradle, have gradle correctly associate the interfaces jar with the grails app.
Ideally I would love to be able to do this just using dependency declaration within gradle, but this is probably a pipe dream...
What are my options?
Add a task into the grails build lifecycle within gradle to build any dependant jars and copy them into the grails lib folder?
Hook into the grails build lifecycle by using Events.groovy or similar to call out to grails to build and package the dependant jars. This would cover both the IntelliJ and command line routes.
Build the interfaces as a grails plugin? I had discounted this as they also need to be used from non-grails projects.
Any help / advice would be appreciated.
Turns out all I needed to do was add the following and then the grails plugin deals with the dependencies for me...
compile project(':dependent-project')
Works nicely for run-app and war...
A partial solution to the problem would be to use both Gradle and Grails maven plug-ins. I have a similar situation where I am building jars that are dependencies of the Grails project.
The approach I've chosen is to install the java artifacts into the local .m2/repo and then declare the dependency under grails/conf/BuildConfig.groovy using the mavenLocal() repo.
What I hadn't considered was to hook gradle into the events lifecycle (interesting idea, btw) and instead defined a gradle project that wraps the grails app (executes test-app, run-app, etc). The gradle wrapper for my grails app has a dependency on the other component's install task so it always checks to see if it needs to be rebuilt.
I'm an Eclipse user so I can't comment on the Intellij part of your question but the above works for me so I hope it gives you some ideas?
My solution for the moment is to:
Use the grails / gradle plugin to build the grails projects.
Use this plugin to run my grails apps, ie. gradle grails-run-app.
Hook into the grails-run-app task in gradle (which is created on the fly) to call a task which builds and copies the dependencies into the lib directory.
This doesn't help a whole load with IntelliJ at the moment but I will run my gradle tasks as IntelliJ run configurations.
My build.gradle is as follows (dependent-project is being jarred and put in lib in this example):
import org.grails.gradle.plugin.GrailsTask
evaluationDependsOn(':dependent-project')
buildscript {
repositories {
mavenCentral()
mavenRepo name: "grails", url: 'http://repo.grails.org/grails/repo'
}
dependencies {
classpath "org.grails:grails-gradle-plugin:1.1.1-SNAPSHOT"
}
}
repositories {
mavenCentral()
mavenRepo name: "grails", url: 'http://repo.grails.org/grails/repo'
}
ext {
version = "1.0"
grailsVersion = "2.2.0.RC2"
grailsTaskPrefix = "grails-"
}
apply plugin: "grails"
dependencies {
['dependencies', 'resources', 'core', 'test', 'hibernate', 'plugin-datasource', 'plugin-domain-class', 'plugin-tomcat', 'plugin-services'].each { plugin ->
compile "org.grails:grails-$plugin:2.2.0.RC2"
}
bootstrap "org.codehaus.groovy:groovy-all:2.0.5"
}
// Get hold of the grails-run-app task (which is created on the fly) and add a dependency to the copyDependencies task
project.gradle.afterProject { p, ex ->
if (p == project) {
project.tasks.addRule("Grails dependencies") { String name ->
if (name.startsWith(grailsTaskPrefix)) {
tasks.getByName(name).dependsOn(copyDependencies)
}
}
}
}
// Build and copy any dependent jar files...
task copyDependencies(type: Sync) {
from project(':dependent-project').configurations.archives.allArtifacts.files
into "$projectDir/lib"
}
When using the grails plugin dsl in BuildConfig.groovy, such as
plugins {
build "org.grails.plugins:db-util:0.4"
}
Is there a way to specify to use a plugin from a zip file like you can do with grails install-plugin?
Not directly, but of you put the zip file in a directory and name it without the grails- prefix, then declare that directory as a flatDir repository then Grails will be able to resolve the plugin from there.
repositories {
flatDir name:'localPlugins', dirs:'../local-plugins'
}
// copy plugin zip to ../local-plugins/my-plugin-1.2.zip
plugins {
compile ':my-plugin:1.2'
}
Or if it's a locally built plugin you could install it into your local maven cache using grails maven-install and just use mavenLocal() instead of the flatDir.
I am running Grails v2.4.0 and I have been trying to install the Grails CXF plugin for web services. I downloaded the .zip file for the plugin and then ran the grails install-plugin /path/to/zip. While trying to install, it gives me an error that it can't find this dependency : org.apache.cxf:cxf-rt-frontend-jaxws:2.3.0. The page where I downloaded this plugin mentions that everything required is in the zip. I can't use maven to download the required files automatically because my work location doesn't allow anything to be downloaded. Is there a list of files required to install CXF manually that I can reference?
Since you can't download the transitive dependencies using Maven, you should be able to exclude them like this:
grails.project.dependency.resolution = {
plugins {
compile ":cxf:0.9.0" {
excludes([ group: 'org.apache.cxf', name: 'cxf-rt-frontend-jaxws']
// you may need to exclude quite a few...
}
}
Then download the dependency manually and put them in your lib directory. For instance, download the cxf-rt-frontend-jaxws from here: http://search.maven.org/#search|ga|1|g%3A%22org.apache.cxf%22%20AND%20a%3A%22cxf-rt-frontend-jaxws%22%20AND%20v%3A%222.3.0%22
Instead of using install-plugin you should add a dependency to the relevant section of your BuildConfig.groovy, and make sure the mavenCentral() repository is enabled. Uninstall the zip plugin you have already installed and then edit your BuildConfig:
grails.project.dependency.resolution = {
// ...
repositories {
// other repositories as before
mavenCentral()
}
plugins {
// other plugins as before
compile ":cxf:0.9.0"
}
}