MyThinkPond

On Java, Python, Groovy, Grails, Spring, Node.js, Linux, Arduino, ARM, Embedded Devices & Web

Archive for the ‘Gradle’ Category

Grails No profile found for name [web] illegalstateexception

Posted by Venkatt Guhesan on November 29, 2016

GrailsMost likely you’ve landed on this page because you’ve searched for the error in a search engine and it brought you here.

Symptom: When you run “grails” under an existing project that you previously had (either on a different PC or from a source-control like GIT or SVN and you’ve mistakenly included the “build” directory).

The associated error would have been one of the following:

Grails No profile found for name [web]

or

java.lang.IllegalStateException: No profile found for name [web].
at org.grails.cli.GrailsCli.initializeProfile(GrailsCli.groovy:507)
at org.grails.cli.GrailsCli.initializeApplication(GrailsCli.groovy:308)
at org.grails.cli.GrailsCli.execute(GrailsCli.groovy:271)
at org.grails.cli.GrailsCli.main(GrailsCli.groovy:162)
| Error Error occurred running Grails CLI: No profile found for name [web]

Either way, here’s how you can quickly resolve this issue and get back in business.

Solution:

Step-1: Remove “.grails” under your “home” directory.

rm -rf ~/.grails/

Step-2: Create a temporary *new* project

cd /temp/</pre>

grails create-app bookstore
# This will create a new scafolding and download the dependencies

Step-3: Remove the “build” directory under your *original* Grails project where you had the problem to begin with.

cd ~/my_original_grails_project/;
rm -rf ./build/
# Remove the old "build" directory

Step-4: Run Grails once again under your *original* Grails project

cd ~/my_original_grails_project/;
grails

You should see a whole bunch of dependencies being downloaded for this project like the following and you will end up with the Grails prompt:

Download https://repo.grails.org/grails/core/com/google/guava/guava/18.0/guava-18.0.pom
Download https://repo.grails.org/grails/core/com/google/guava/guava-parent/18.0/guava-parent-18.0.pom
Download https://repo.grails.org/grails/core/net/java/dev/jna/jna/4.1.0/jna-4.1.0.pom
Download https://repo.grails.org/grails/core/org/eclipse/jetty/jetty-util/9.2.18.v20160721/jetty-util-9.2.18.v20160721.pom
Download https://repo.grails.org/grails/core/org/eclipse/jetty/jetty-io/9.2.18.v20160721/jetty-io-9.2.18.v20160721.pom
Download https://repo.grails.org/grails/core/org/eclipse/jetty/websocket/websocket-common/9.2.18.v20160721/websocket-common-9.2.18.v20160721.pom
Download https://repo.grails.org/grails/core/org/eclipse/jetty/websocket/websocket-api/9.2.18.v20160721/websocket-api-9.2.18.v20160721.pom
Download https://repo.grails.org/grails/core/org/grails/grails-plugin-testing/3.1.10/grails-plugin-testing-3.1.10.jar
Download https://repo.grails.org/grails/core/org/grails/grails-test/3.1.10/grails-test-3.1.10.jar
Download https://repo.grails.org/grails/core/org/springframework/boot/spring-boot-starter-test/1.3.7.RELEASE/spring-boot-starter-test-1.3.7.RELEASE.jar
Download https://repo.grails.org/grails/core/org/seleniumhq/selenium/selenium-support/2.47.1/selenium-support-2.47.1.jar
Download https://repo.grails.org/grails/core/org/seleniumhq/selenium/selenium-remote-driver/2.47.1/selenium-remote-driver-2.47.1.jar
Download https://repo.grails.org/grails/core/org/eclipse/jetty/websocket/websocket-client/9.2.18.v20160721/websocket-client-9.2.18.v20160721.jar
Download https://repo.grails.org/grails/core/org/seleniumhq/selenium/selenium-api/2.47.1/selenium-api-2.47.1.jar
Download https://repo.grails.org/grails/core/com/google/guava/guava/18.0/guava-18.0.jar
Download https://repo.grails.org/grails/core/net/java/dev/jna/jna/4.1.0/jna-4.1.0.jar
Download https://repo.grails.org/grails/core/org/eclipse/jetty/jetty-util/9.2.18.v20160721/jetty-util-9.2.18.v20160721.jar
Download https://repo.grails.org/grails/core/org/eclipse/jetty/jetty-io/9.2.18.v20160721/jetty-io-9.2.18.v20160721.jar
Download https://repo.grails.org/grails/core/org/eclipse/jetty/websocket/websocket-common/9.2.18.v20160721/websocket-common-9.2.18.v20160721.jar
Download https://repo.grails.org/grails/core/org/eclipse/jetty/websocket/websocket-api/9.2.18.v20160721/websocket-api-9.2.18.v20160721.jar
Download https://repo.grails.org/grails/core/org/grails/profiles/web/3.1.9/web-3.1.9.pom
Download https://repo.grails.org/grails/core/org/grails/profiles/base/3.1.9/base-3.1.9.pom
Download https://repo.grails.org/grails/core/org/grails/profiles/web/3.1.9/web-3.1.9.jar
Download https://repo.grails.org/grails/core/org/grails/profiles/base/3.1.9/base-3.1.9.jar
| Enter a command name to run. Use TAB for completion:
grails>

Now you’re all set and ready to go.

Cheers!

Today’s inspirational quote:
bust_of_marcusaurelius
  • When you need encouragement, think of the qualities the people around you have: this one’s energy, that one’s modesty, another’s generosity, and so on. Nothing is as encouraging as when virtues are visibly embodied in the people around us, when we’re practically showered with them. It’s good to keep this in mind.
  • You have power over your mind—not outside events. Realize this, and you will find strength.

Posted in Gradle, Grails, Java, Spring, Spring Framework | Tagged: , , , , , | Leave a Comment »

Gradle Spring Woes: Issues in creating single jar bundle with all dependency jars nested within

Posted by Venkatt Guhesan on November 3, 2016

springframeworkIf you’re implementing any projects with Spring and Gradle (for build), as your project grows you may run into this issue. Or you’ve landed on this page by searching on Google for “Unable to locate Spring NamespaceHandler for XML schema namespace” (your actual XML that it’s error-ing out may vary).

Either way, you’re in luck! Most likely, you’re using the fatjar gradle plugin to create a single JAR for executing as “java -jar one-big-bundle.jar”. The problem that happens is that if two or more dependent jar libraries contain the same file/artifact, then the last one wins the race in the fatjar bundle.

Let me illustrate this with an example:

Let’s say that your project depends on Spring-Context and Spring-Core. Within each jar, there maybe resources that have a common name such as META-INF/spring.schemas and/or META-INF/spring.handler (To learn more about the two individual files and their purpose in Spring, click on the links). When the fatjar combines the two JAR file, depending upon who goes last, the version of the above two files may belong to one or the other library. What should happen in reality is that it merges the two files contents. They maybe good for some files. But if you have a specific file in a format where you simply cannot concatenate the two files (such as a nested XML or JSON), simply combining the two files will not work. You may need to extend the Gradle plugin tasks to perform something selective and unique to your situation.

But if you ended up here after searching for “Unable to locate Spring NamespaceHandler for XML schema namespace” message, there is hope. You can simply, add the following to the fatJar Gradle plugin and problem is solved:

fatJarPrepareFiles {
  include 'META-INF/spring.handlers'
  include 'META-INF/spring.schemas'
}

A second option is to use a newer plugin called shadow. [User Guide]

...
apply plugin: 'com.github.johnrengelman.shadow'
...
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4'
    }
}
...
//For building a single jar with all dependencies run "gradlew shadowJar"
// Configure the shadow jar task
shadowJar {
    mergeServiceFiles()
}

jar {
    manifest {
        attributes 'Implementation-Title': 'application name',
                'Implementation-Version': version,
                'Main-Class': 'com.guhesan.fooapp.Application'
    }
}

Cheers!

Today’s Inspirational Quote:

…Bliss is not something to be got.
On the other hand you are always Bliss.
This desire [for Bliss] is born of the sense of incompleteness.
To whom is this sense of incompleteness? Enquire.
In deep sleep you were blissful.
Now you are not so.
What has interposed between that Bliss and this non-bliss?
It is the ego.
Seek its source and find you are Bliss.
Ramana Maharishi|2nd link (Spiritual Teacher & one of the great minds of this century)

-AUM

Posted in Gradle, Grails, Spring, Spring Framework | Tagged: , , , , , | Leave a Comment »