I have a groovy/grails jar file. I want to decompile it into groovy files. Is there any tool to do that. I have tried some online decopilers , they all decmpile the files into java not groovy. I have created the jar using gradle jar command. I'm using grails version 3.1.11 and groovy version: 2.4.7 and gradle verion: 2.13
You can use any Java decompiler, but you will not get Groovy code back, as no such tool exists (to my knowledge)
This is one of the weaknesses of non-Java JVM languages. Groovy does a lot of reflection and other such trickery in creating its bytecode, so if you decompile the .class file, you'll have a lot of noise. This is similarly reflected in Groovy stacktraces. You have to train yourself to find the signal despite all of the noise. The good news is that both Eclipse and IntelliJ can debug Groovy code nicely, so you can step through to find the issue you're dealing with.
Related
If I'm looking at project source code (in Intellij) how can I tell whether the Grails source code I'm looking at is an Application or a Plugin?
I get it that the output of a Grails Application build is a WAR, and a JAR for a Plugin but I can't figure out how to tell the difference by looking at the source code.
Bonus question: If it is a multi-module project, how do I tell which module is the Application and which modules are the Plugins? Or am I missing some important concept here?
Plugins can be run as applications as well and will often have an Application.groovy file. Plugins will have a <pluginname>GrailsPlugin.groovy file which sets up the plugin. In grails 3, this is in /src/main/groovy file structure.
I've successfully used Grails's inline / inplace plugin notation to develop my Grails app and several plugins concurrently. I only have to compile my Grails app and all the inline plugins get compiled too (great!):
grails.plugin.location.myFooPlugin = '../plugins/foo-plugin'
Can I do the same thing for a Java dependency rather than a Grails plugin?
Let's say I have some Java project that ultimately produces a JAR, but rather than compile and store the JAR in my Maven local repo I'd like to simply compile my Grails app and have the Java project's code also compiled as a result. Possible? If so, what are the rules, such as dir structure adherence? I might want to use Gradle or Maven, not sure.
I'm using a java dependency in my Grails project with help of /scripts/_Events.groovy:
eventCompileStart = {
projectCompiler.srcDirectories << "${basedir}/../your_java_proj/src".toString()
}
The java project will be compiled automatically along with e.g. grails war commando.
I'm trying to diagnose a failure in my ant file when it runs a Worklight task. I have a small ant file containing a simple reference to a Worklight task. This works correctly.
<target name="rawBuildApplication" >
<app-builder
applicationFolder="${applicationSource}"
environments="mobilewebapp"
nativeProjectPrefix="xxx"
outputFolder="${outputFolder}"/>
</target>
However when I invoke this ant file from a build control ant file (actually from the RTC build system) I get a failure (below), showing worklight failing to find an apache Java class. I assume there's some simple environmental difference, perhaps a classpath. It might help to figure it out if I knew where Worklight loaded the apache commons from. Right now I can't see anything in my environment in the case that works that points any apache Jar.
myAntFile.xml:146: java.lang.NoSuchMethodError: org.apache.commons.io.FileUtils.deleteQuietly(Ljava/io/File;)Z
at com.worklight.builder.util.BuilderUtils.<clinit>(BuilderUtils.java:672)
at com.worklight.builder.config.UserBuildConfiguration$Builder.<init>(UserBuildConfiguration.java:203)
at com.worklight.ant.builders.ApplicationBuilderTask.createBuildConfiguration(ApplicationBuilderTask.java:149)
at com.worklight.ant.builders.ApplicationBuilderTask.execute(ApplicationBuilderTask.java:80)
Edited: the cause is the use of -lib to add the RTC toolkit directory, exactly why this clashes and how to work around yet to be determined
Usually means you have version of the commons jar in your classpath, and its overriding the one packaged in the worklight-ant.jar. the apache commons files are inside the worklight-ant.jar file
Additional info from djna: I can confirm that when adding the Rational Team Concert (RTC) 3.0 toolkit to the ant classpath, either explicitly with -lib, or when selecting that option in the RTC Build definition some conflicting commons jars are added to the classpath. Worklight packages the classes it needs in its jar, but the -lib folder seems to take precedence.
My workaround is to replace the conflicting jars with later ones. I used these jars
commons-io-2.4.jar
commons-codec-1.8.jar
httpclient-4.2.5.jar
httpcore-4.2.4.jar
httpmime-4.2.5.jar
I guess the other alternative is to upgrade to a newer RTC, but in our environment that's not currently possible.
What approach has worked well for you combining IVY + msbuild?
Our goal is to integrate IVY into the C#/C++ build process for dependency resolution and publishing. We have tried adding it to custom tasks at the beginning and end of the build and we have tried wrapping the msbuild calls with ant+ apache-ant-dotnet.
Other options might be gradle, buildr, rake.
What do you use?
Thanks
Peter
Most build technologies can use libraries found in a local directory. I'd suggest using the command-line ivy program to populate this, at the start of your build:
java -jar ivy.jar -ivy ivy.xml -settings ivysettings.xml -retrieve "lib/[conf]/[artifact].[ext]"
Your dependencies are listed in a standard ivy file called ivy.xml. The protocol, location and layout of your remote repository is described in ivysettings.xml
The advantage of this approach (as opposed to switching to Gradle, etc) is that you're not trying to replace your existing build tool. Ivy is solely concerned with managing dependencies.
My team has been using Ivy for .NET for a couple of years very successfully. I know several more that give it a vote of confidence.
Use it standalone. Wrap calls into msbuild tasks. No need to use Ant integration.
Does PMD works with grails project, i.e. with .groovy files??
i'm using STS editor,
if it works, what setup i have to do?
Please let me know, if anyone have any idea
Thanks in advance
I'm not aware of any PMD plugin for Groovy/Grails. However, there is a CodeNarc Grails plugin, which does similar kinds of static analysis on Groovy/Grails code.
codeNarc is one of the best choices for grails projects, thou it is ignoring java classes that potentially are part of your project.
I have not seen any pmd or findBugs plugins for grails that would take care of the java portion. You can use the STS/Eclipse PMD plugin thou to analyze explicitly the src/java/ folder.
Unfortunately the findBugs eclipse-plugin is not able to limit to a certain parts of the project so it no big use (findBugs works purely on class files and works through the complete project).
I guess it should be possible to write a grails pmd plugin that would analyze the java parts of a grails project.
Starting with Grails 3, the build system uses Gradle. There is a PMD gradle plugin which you could use to perform static analysis on your java source files. There is also a Codenarc gradle plugin which you can use to perform analysis on the groovy files in your project.
https://docs.gradle.org/current/userguide/pmd_plugin.html