Configure Artifactory with grails project - grails

I am trying to configure a Grails project with remote Artifactory but failing to configure it properly.
Envionmanet setup
grails-2.4.3
artifactory.version 3.3.0
BuildConfig.groovy
grails.project.dependency.resolver = "maven" // or ivy
grails.project.ivy.authentication = {
repositories {
mavenRepo "http://SERVER/artifactory/grails-remote"
}
credentials {
realm = "Artifactory Realm"
host = "SERVER"
username = "USERNAME"
password = "PASSWORD"
}
}
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// specify dependency exclusions here; for example, uncomment this to disable ehcache:
// excludes 'ehcache'
}
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
checksums true // Whether to verify checksums on resolve
legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility
repositories {
inherits true // Whether to inherit repository definitions from plugins
mavenRepo id: 'Artifactory', url: "http://SERVER/artifactory/grails-remote"
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
// runtime 'mysql:mysql-connector-java:5.1.29'
// runtime 'org.postgresql:postgresql:9.3-1101-jdbc41'
test "org.grails:grails-datastore-test-support:1.0-grails-2.4"
}
plugins {
// plugins for the build system only
build ":tomcat:7.0.55"
// plugins for the compile step
compile ":scaffolding:2.1.2"
compile ':cache:1.1.7'
compile ":asset-pipeline:1.9.6"
compile ":rabbitmq:1.0.0"
// plugins needed at runtime but not for compilation
runtime ":hibernate4:4.3.5.5" // or ":hibernate:3.6.10.17"
runtime ":database-migration:1.4.0"
runtime ":jquery:1.11.1"
}
}
Getting the below exception after executing the refresh-dependencies command for the project
Loading Grails 2.4.3
|Configuring classpath
Error |
Resolve error obtaining dependencies: The following artifacts could not be resolved: org.grails.plugins:scaffolding:zip:2.1.2, org.grails.plugins:cache:zip:1.1.7, org.grails.plugins:webxml:zip:1.4.1, org.grails.plugins:asset-pipeline:zip:1.9.6, org.grails.plugins:rabbitmq:zip:1.0.0, org.grails.plugins:hibernate4:zip:4.3.5.5, org.grails.plugins:database-migration:zip:1.4.0, org.grails.plugins:jquery:zip:1.11.1: Could not find artifact org.grails.plugins:scaffolding:zip:2.1.2 in Artifactory (http://SERVER/artifactory/grails-remote) (Use --stacktrace to see the full trace)
Error |
Resolve error obtaining dependencies: The following artifacts could not be resolved: org.grails.plugins:scaffolding:zip:2.1.2, org.grails.plugins:cache:zip:1.1.7, org.grails.plugins:webxml:zip:1.4.1, org.grails.plugins:asset-pipeline:zip:1.9.6, org.grails.plugins:rabbitmq:zip:1.0.0, org.grails.plugins:hibernate4:zip:4.3.5.5, org.grails.plugins:database-migration:zip:1.4.0, org.grails.plugins:jquery:zip:1.11.1: Could not find artifact org.grails.plugins:scaffolding:zip:2.1.2 in Artifactory (http://SERVER/artifactory/grails-remote) (Use --stacktrace to see the full trace)
Error |
Resolve error obtaining dependencies: The following artifacts could not be resolved: org.grails.plugins:scaffolding:zip:2.1.2, org.grails.plugins:cache:zip:1.1.7, org.grails.plugins:webxml:zip:1.4.1, org.grails.plugins:asset-pipeline:zip:1.9.6, org.grails.plugins:rabbitmq:zip:1.0.0: Could not find artifact org.grails.plugins:scaffolding:zip:2.1.2 in Artifactory (http://SERVER/artifactory/grails-remote) (Use --stacktrace to see the full trace)
Error |
The following artifacts could not be resolved: org.grails.plugins:scaffolding:zip:2.1.2, org.grails.plugins:cache:zip:1.1.7, org.grails.plugins:webxml:zip:1.4.1, org.grails.plugins:asset-pipeline:zip:1.9.6, org.grails.plugins:rabbitmq:zip:1.0.0: Could not find artifact org.grails.plugins:scaffolding:zip:2.1.2 in Artifactory (http://SERVER/artifactory/grails-remote)
|Run 'grails dependency-report' for further information.
Process was killed
I have read and tried couple of solutions as described in below link but it couldn't help
How to configure grails 2.4.0 to resolve artifacts from artifactory with authentication?
http://wordpress.transentia.com.au/wordpress/2014/04/09/artifactory-and-grails/
Update1:
After looking closely into Artifactory's apache catalina log I found that for some of plugins it is causing some forbidden error.
2014-10-15 15:16:19,596 [ajp-bio-8019-exec-10] [INFO ] (o.a.r.s.RepositoryBrowsingServiceImpl:236) - Error while listing remote resources for codehaus/org/grails/grails-datastore-gorm-mongo: Unable to retrieve http://repository.codehaus.org/org/grails/grails-datastore-gorm-mongo/: 403: Forbidden
Can anyone please help me to find out whats wrong with configuration?
Greetings,
Mayank

Rather than defining the repository authentication with grails.project.ivy.authentication, You should probably define the repository with:
grails.project.dependency.resolution = {
repositories {
grailsCentral()
....
mavenRepo(name: 'name', url: 'https://host/artifactory/reponame') {
auth(username: 'username', password: 'password')
}
....
}
}

Related

Grails dependency error-only looks in grailsCentral not other repos

Grails 2.5...
I have a plugin in an SVN repository.
Here is the build config (minus authentication credentials)....
grails.project.dependency.resolver = "maven" // maven or ivy
grails.project.dependency.resolution = {
inherits("global") {
// specify dependency exclusions here; for example, uncomment this to disable ehcache:
// excludes 'ehcache'
}
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
checksums true // Whether to verify checksums on resolve
legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility
repositories {
inherits true // Whether to inherit repository definitions from plugins
grailsPlugins()
grailsHome()
grailsCentral()
mavenLocal()
mavenCentral()
mavenRepo "http://repo.grails.org/grails/plugins"
mavenRepo name:"*********", root: "*********************"
}
plugins {
runtime ':org-calendar-viewer:0.7.9'
}
But I always get a dependency resolve error it could not find the plugin at grailsCentral. Of course it couldn't the plugin is in a different repo. Is grailsCentral the last place it looks? Or the first place it looks?
Resolve error obtaining dependencies: Could not find artifact in grailsCentral (https://repo.grails.org/grails/plugins)
I tried commenting out the grails repos and then it fails as
Resolve error obtaining dependencies: Could not find artifact in mavenCentral (https://repo1.maven.org/maven2/)
So it seems it is throwing an error after only checking one(first) location?

Grails plugin dependency pulled into maven cache, but main project can't resolve classes

Using Grails 2.5.4
I have a plugin that uses the Twilio SDK (7+).
The plugin packages without error.
When I run the main project it throws an error saying that the it
cannot resolve the import com.twilio.Twilio class in the plugin
controllers/services.
I confirm that the Twilio SDK has been pulled into the local Maven
cache when the plugin was pulled in, so it knows to get the dependency.
The main project BuildConfig includes mavenLocal() in the dependency
resolution.
Where do I look next to find the cause of this dependency resolution problem?
plugin dependencies.groovy
grails.project.dependency.resolver = "maven"
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// excludes 'ehcache'
}
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility
repositories {
grailsCentral()
// uncomment the below to enable remote dependency resolution
// from public Maven repositories
mavenLocal()
mavenCentral()
}
dependencies {
compile 'com.twilio.sdk:twilio:7.8.0'
}
in plugin.xml
<dependencies>
<compile>
<dependency group='com.twilio.sdk' name='twilio' version='7.8.0' />
</compile>
</dependencies>
In main project BuildConfig.gorrcy
plugins{
compile ":twilio-ext:1.0"
}
running grails dependency-report I see
org.grails.plugins:twilio-ext:1.0
But it has no sub dependencies listed.

Grails - Database Reverse Engineer plugin not found

Environment
Grails 2.4.4
PostgreSQL 9.4
JDK 1.7
I've been trying to get this plugin to work. (I'm still a grails newbie, not to mention programming.)
I tried to do everything I can find out there but still get this untimate error message.
Loading Grails 2.4.4
|Configuring classpath
|Running pre-compiled script
|Script 'DbReverseEngineer' not found, did you mean:
1) SetVersion
2) GenerateRestfulController
3) GenerateViews
4) GenerateController
5) DbmGenerateChangelog
Please make a selection or enter Q to quit:
This is what I have right not in my config files. (I've tried to change a lot of them, such as Hibernate, plugin version etc, but always end up with that message.)
grails.project.dependency.resolver = "maven"
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// specify dependency exclusions here; for example, uncomment this to disable ehcache:
// excludes 'ehcache'
}
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
checksums true // Whether to verify checksums on resolve
legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility
repositories {
inherits true // Whether to inherit repository definitions from plugins
grailsPlugins()
grailsHome()
mavenLocal()
grailsCentral()
mavenCentral()
// uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories
mavenRepo "http://repository.codehaus.org"
//mavenRepo "http://download.java.net/maven/2/"
mavenRepo "http://repo.grails.org/grails/repo/"
mavenRepo "http://repository.jboss.com/maven2/"
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
// runtime 'mysql:mysql-connector-java:5.1.29'
test "org.grails:grails-datastore-test-support:1.0.2-grails-2.4"
runtime "org.postgresql:postgresql:9.4-1205-jdbc41"
compile "org.grails.plugins:db-reverse-engineer:4.0.0"
}
plugins {
// plugins for the build system only
build ":tomcat:7.0.55"
// plugins for the compile step
compile ":scaffolding:2.1.2"
compile ':cache:1.1.8'
compile ":asset-pipeline:1.9.9"
compile ":postgresql-extensions:4.6.1"
compile ":jquery:1.11.1"
compile ":joda-time:1.5"
compile "org.grails.plugins:db-reverse-engineer:4.0.0"
// plugins needed at runtime but not for compilation
runtime ":hibernate4:4.3.6.1"// or ":hibernate:3.6.10.18"
runtime ":database-migration:1.4.0"
runtime ":jquery:1.11.1"
runtime ":db-reverse-engineer:4.0.0"
}
Thanks in advance.
EDIT 1
So, I changed DbReverseEngineer.groovy under Script folder like this.
mergedConfig.driverClassName = dsConfig.driverClassName ?: 'org.postgresql.Driver'
mergedConfig.password = dsConfig.password ?: ''
mergedConfig.username = dsConfig.username ?: 'postgres'
mergedConfig.url = dsConfig.url ?: 'jdbc:postgresql://localhost:5432/myApp'
And I changed plugin and dependency per Burt's and Emmanuel's advice. And when I run grails db-reverse-engineer command I get this error.
Compilation error: startup failed:
Compile error during compilation with javac.
/home/Documents/Grails_Workspace/myApp/target/work/plugins/cache-1.1.8/src/java/grails/plugin/cache/web/GenericResponseWrapper.java:203: error: method does not override or implement a method from a supertype
#Override
^
/home/Documents/Grails_Workspace/myApp/target/work/plugins/cache-1.1.8/src/java/grails/plugin/cache/web/filter/PageFragmentCachingFilter.java:389: error: cannot find symbol
contentType = response.getContentType();
^
symbol: method getContentType()
location: variable response of type HttpServletResponse
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
What are those errors mean and how can I get rid of it?
Thanks.
You've got the same plugin set up twice:
compile 'org.grails.plugins:db-reverse-engineer:4.0.0'
runtime ':db-reverse-engineer:4.0.0'
According to the plugin's page it should be configured as a compile time dependency:
compile "org.grails.plugins:db-reverse-engineer:4.0.0"
The plugin does have the command that's claimed to be missing. You can see it here. So you may need to refresh the dependencies by running:
grails refresh-dependencies

Grails can't load maven-publisher

I am trying to add maven-publisher to a Grails (2.3.6) plugin like so:
dependencies {
compile 'org.mongodb.morphia:morphia:0.107'
compile ":maven-publisher:0.8.1"
}
When I run grails compile I get:
| Error There was an error loading the BuildConfig: Bad artifact coordinates
:maven-publisher:0.8.1, expected format is <groupId>:<artifactId>[:<extension>[
:<classifier>]]:<version> (Use --stacktrace to see the full trace)
What's going on here?
Do not use the maven-publisher plugin. It's old and deprecated. Use the release plugin - it should already be in your plugin's BuildConfig.groovy. If not, here's how it should look (after removing unnecessary cruft):
grails.project.work.dir = 'target'
grails.project.dependency.resolution = {
inherits 'global'
log 'warn'
repositories {
grailsCentral()
mavenLocal()
mavenCentral()
}
dependencies {
compile 'org.mongodb.morphia:morphia:0.107'
}
plugins {
build ':release:3.0.1', ':rest-client-builder:1.0.3', {
export = false
}
}
}
As #dmahapatro said in his comment, jar dependencies go in the dependencies block, and plugin dependencies go in the plugins block.
Note also that you should keep the export = false setting so the plugin is available locally for your use, but doesn't leak into the containing application as an unnecessary transitive dependency.

Grails not picking jars from Maven repository based on pom.xml

I am getting some compilation error because of Grails not picking jars from Maven repository based on pom.xml file.
My BuildConfig.groovy
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// uncomment to disable ehcache
// excludes 'ehcache'
//excludes "grails-plugin-log4j"
}
log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
checksums true // Whether to verify checksums on resolve
//excludes "grails-plugin-log4j"
pom true
repositories {
inherits true // Whether to inherit repository definitions from plugins
//grailsPlugins()
/// grailsHome()
// grailsCentral()
mavenCentral()
mavenLocal()
// These are for the hudson machine
// mavenRepo "/apps/profiler/ci/hudson/workspace/RMSPortal2/m2_repo"
// mavenRepo "/apps/profiler/ci/hudson/workspace/RMSPortal2/m2_repo"
//mavenRepo "http://snapshots.repository.codehaus.org"
//mavenRepo "http://repository.codehaus.org"
// mavenRepo "http://download.java.net/maven/2/"
//mavenRepo "http://repository.jboss.com/maven2/"
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
runtime 'mysql:mysql-connector-java:5.1.5'
compile 'org.apache.activemq:activemq-core:5.3.0'
test 'org.objenesis:objenesis:1.2'
compile 'org.slf4j:slf4j-log4j12:1.6.6'
//compile "spring-security-config:3.0.1.RELEASE"
}
plugins {
compile ":spring-security-core:1.2.7.3"
compile ":spring-security-ui:0.2"
compile ":jquery-ui:1.8.15"
compile ":jqgrid:3.8.0.1"
compile ":famfamfam:1.0.1"
compile ":mail:1.0"
compile ":jms:1.2"
compile ":calendar:1.2.1"
compile ':gpars:0.3'
compile ":lang-selector:0.3"
compile ":crypto:2.0"
compile ":grails-melody:1.13"
runtime ":hibernate:$grailsVersion"
runtime ":jquery:1.7.1"
//runtime ":resources:1.1.6"
runtime ":resources:1.2.RC2"
runtime ":export:1.5"
// Uncomment these (or add new ones) to enable additional resources capabilities
//runtime ":zipped-resources:1.0"
//runtime ":cached-resources:1.0"
//runtime ":yui-minify-resources:0.1.4"
build ":tomcat:$grailsVersion"
test ":spock:0.6"
}
}
I am getting error like this:
Configuring classpath.
| Environment set to development.....
| Packaging Grails application.....
| Compiling 141 source files.
| Error Compilation error: startup failed:
/mycompany/dev/rmaddidev/wsmavenTest/pro/src/groovy/com/mycompany/rms/common/RMSExportService.groovy: 15: unable to resolve class org.xhtmlrenderer.pdf.ITextRenderer
# line 15, column 1.
import org.xhtmlrenderer.pdf.ITextRenderer
^
1 error
ITextRenderer class exist in core-renderer.jar i specified in maven pom as below.
if i add those jars in BuildConfig.groovy, then it working fine.
compile 'org.xhtmlrenderer:core-renderer:R8'
compile 'com.lowagie:itext:2.0.8'
And My Pom file:
<dependencies>
<dependency>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>core-renderer</artifactId>
<version>R8</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.0.8</version>
</dependency>
You can still use the standard grails commands as long as all your dependencies are referenced in the BuildConfig.groovy.
However, you probably don't want to maintain both the Maven POM and BuildConfig.groovy, unless you have some team members who don't want to use Maven.
Unless the project needs to be 'buildable' using both Maven and the standard Grails command line, avoid the BuildConfig.groovy at all costs, as well as the Grails command line.
Details
When using Maven, you need to do the following :
Do not set dependencies in BuildConfig.groovy, add them to your POM:
The dependencies block from your BuildConfig.groovy move to the POM(with the default implied type tag set to jar).
For non jar dependencies(plugins or non-binary plugins), you need to explicitly set the dependency type to zip in your pom.xml.
Also, remove the repositories block from your BuildConfig.groovy, and set the repositories in your POM.
Do not use the grails command line, use the Grails Maven goals, as implied by #dmahapatro.
When you decide to use Maven and Grails, it implies that you want avoid having settings in your BuildConfig.groovy.
Then you'd have your build settings(all if it were 100% possible) driven by the Maven POM.

Resources