Including Liferay .jars in groovy for portlet development - grails

We are developing liferay portlets in groovy using the portlets and liferay portlets plugins. We wanted to find the user ID of the current user logged in. In order to do that, using the com.liferay.model.user class was suggested (from searching on other S.O. questions).
Unfortunately, when we try to import com.liferay.* (or com.liferay.model.user etc.) the grails complier cannot resolve the 'user' class. This makes sense, since the com.liferay folder is not in the grails/lib folder. However, I am unable to find out where to acquire these .jar files to add them to the lib folder in grails.
Am I approaching this wrong?
(Note: I am using Liferay 5.2.3, not the newest version of liferay)
Or, in 5.2.X is there an easier way to get the ID or name of the currently logged in user?

[UPDATED]
mvnrepository.com isn't a repository itself, it's a search engine for Maven artifacts.
By looking at the "Download jar hyperlink", I see that the liferay jars are available in Maven Central http://repo1.maven.org/maven2/com/liferay/portal/.
In the repositories section of your BuildConfig.groovy, make sure that the following line is there
mavenCentral()
I think the portal-impl artifact contains com.liferay.model.user.* related classes which are what you're looking for.
In that case you would have the following dependency in your BuildConfig.groovy
compile 'com.liferay.portal:portal-impl:5.2.3'
If you require additional liferay classes, assuming you have liferay running somewhere, you could search the jars for a specific class name (http://java.net/projects/jarscan). Once you know the jar name, you can search it on mvnrepository.com and add the relevant dependency to your BuildConfig.groovy.
Hope it helps.
You can reference liferay dependencies in your BuildConfig.groovy. You would need to confirm the repository URL and then it should be fine.
http://mvnrepository.com/artifact/com.liferay.portal
You could exclude those dependencies from packaging.

Related

How to access domain classes from a custom plugin to another?

I am currently working on grails project. I have created eight different plugins. Each having a set of Domain classes and other stuffs. Now, from one of my plugins, a certain Domain class needs to access a domain class from the other plugin. How will I do that? Do I have to import the domain classes from the other plugin? If so, how? or Shall I do that in BuildConfig.groovy?
Please help!
Thanks!
Simple make the plugin that need other plugin domains dependent from it in buildconfig
//buildConfig of plugins need other plugin domains
grails.project.dependency.plugins{
...
compile ':<other-plugin-name>:<other-plugin-version>'
...
}
The simply import the right package where you need it.
If you are constantly working on the depended plugin and you don't want to repackage it constantly you can connect it using grails.plugin.location instead of grails.project.dependency.plugins.
in buildConfig add
grails.plugin.location.'other-plugin-name' = "/path/to/other/plugin/folder"

How to configure db-reverse-engineer plugin

I am a total Grails noob trying to configure the db-reverse-engineer plugin for my first project. Documentation for the plugin indicates that I need to configure it, but I don't see where I am supposed to edit configuration.
Is there a configuration file in my project I need to edit? I have searched through the ./grails-app/conf folder for grails.plugin (the prefix for this plugin's configuration) and found nothing. An SO or Google search for how to configure grails plugins also returns void. I know this is a lame question, but how do I configure this plugin? Is there a UI I need to use, or are there files somewhere to edit?
You need to configure your database in grails-app/conf/DataSource.groovy. In particular, you'll need to provide the JDBC URL, the database dialect and the databases's username and password.
You'll also have to add some extra db-reverse-engineer configuration to grails-app/conf/Config.groovy. This file will already exist. Just append the new properties at the end.
Finally, run the reverse engineer script to generate your domain classes:
grails db-reverse-engineer
The right place for that would be the file grails-app/conf/Config.groovy.
Just add what you need at the bottom.

plugin-info.html not being generated for Maven site

I have a custom Maven plugin for which I want to generate a site. The sole purpose of this site is to automatically document the plugin's available goals. However, when I execute mvn clean site, the plugin-info.html file is never generated.
Given that the packaging for this module is maven-plugin, I assumed that this would automatically be created by the site plugin. I looked at the site plugin's goals to see if this had to explicitly be "turn on", but did find anything. Is there something I am missing that will force the plugin-info.html to be created?
I am using:
Maven 3.0.3
maven-site-plugin 3.0
After some debugging I made a jira issue at http://jira.codehaus.org/browse/MPLUGIN-191. The description contains the workaround I found to fix this problem.

How can I access a file in my Grails plugin from a src file in the same plugin?

I'm working on a JavaScript testing plugin for Grails. I wrote some Groovy classes to perform the testing that I've stored in my src/groovy folder. I hook into the testing events in my plugin's _Events.groovy script and inject an instance of the test runner. From that instance of the test runner, I need to access the JavaScript files, which I've stored in src/js, to perform the testing.
The plugin documentation specifies a way to get the path from my Gant scripts, but that doesn't work elsewhere. I've also tried to get access to the GrailsApplication via grailsApplication or ApplicationHolder, but I get null. Finally, I've tried accessing BuildSettings and ConfigurationHolder, but those show me an empty configuration.
To make my plugin work, I am currently copying the JavaScript files into the application's test/resources folder so it's in a known location relative to the working directory, which I'm assuming is the project folder. This feels invasive and fragile to me, so I'd like to figure out a "right" way.
How can I get a path to my plugin from my test runner so I can find those files?
If you have the BuildSettings and the pluginManager bean (either dependency-injected with def pluginManager or via PluginManagerHolder) then you can get the path with
new File(buildSettings.projectPluginsDir, pluginManager.getPluginPath('foo'))

Specifying order of plugins in Grails

My grails application depends on several grails plugins that append and entries to web.xml
The problem is I need to control the order the plugins are executed. There is a particular plugin which is used for some security purposes which adds a filter in web.xml. This filter needs to be the first executed filter in web.xml Thus I would like this filter to be executed last so that I can ensure that this plugin will be appending the configurations in the first position.
I know there is a dependsOn property on the plugin class to ensure it gets executed last, but that only works if I know which plugins are going to be used in combination with this plugin. I would like this plugin to be general enough so that anyone in my company can use this plugin and know for sure that this gets executed last.
Is there any way I can ensure a particular plugin gets executed last? Either in the grails-plugin project (ie a property of the plugin class) or configuration of the grails application project.
Thanks,
Does the grails application install plugins using the install-plugin command? If so, try declaring them in BuildConfig.groovy instead.
plugins {
runtime ':weceem:0.8'
runtime ':hibernate:latest.release'
}
It's possible that plugins declared here are loaded in the same order they're listed, though I haven't tested this theory.
It might be easier to find a way to make your plugin append it's filters differently to ensure they get appended to the position you want them in. I would have to see the code for the plugin if I was going to try to help solve this in that way though.

Resources