Grails: how to use Maven repo instead of ivy-cache - maven

I need to use Maven Repository instead of ivy-cache, what are the steps I have to do? I tried multiple ways but it not working.
I specified in BuildConfig.groovy
pom true
repositories {
inherits true // Whether to inherit repository definitions from plugins
//grailsPlugins()
//grailsHome()
//grailsCentral()
and I deleted ivy-cache folder, it(run-app) creating again and downloading all jars again. I found some help from here:
ivysettings.xml: add local maven path
I did same changes, even there is no result. My changed in C:\Program Files (x86)\grails-2.1.4\src\grails\ant\ivysettings.xml. I think I have to copy this file in our application, but I don't know where?

1) I don't think that you can "disable" the ivy-cache. However you can customize its location:
grails.dependency.cache.dir = "C:\\.ivy2"
As far as I know Grails will not read your ivy settings, you need to plug your resolvers yourself.
See this SO question : In Grails, how do I specify jars needed by an ivy resolver?
2) If you problem is only related to maven/grails integration, you can try the following screencast(baby steps) that I created : http://www.youtube.com/watch?v=tqGN61hiciE&list=PLYdLfOs5pdSjWsZCZRnYAQAm78nEFYxhd
Then, in your Maven pom.xml, just add your repositories as usual.
In your BuildConfig.groovy, add pom true and remove repositories declarations as well as the dependencies and plugins sections.
grails.project.dependency.resolution = {
…
pom true
...
}
Hope it helps

Related

Cannot import com.tibco.tibjms.TibjmsQueueConnectionFactory with Gradle

so I've been working on migrating a Maven project over onto a Gradle one. While doing so, I can across a class called TibjmsQueueConnectionFactory that I've been trying to figure out how trying to import. I've found most of my other imports on MVNRepository however, none of the ones I try for this one seem to work.
This is basically all I'm trying to do:
// https://mvnrepository.com/artifact/com.tibco/tibjms
implementation group: 'com.tibco', name: 'tibjms', version: '1.0'
I did see somewhere that Tibco may not exist at that location at all, and maybe I'll have to download a jar file, but I'm not sure if this is the case or not. Has anyone else had this issue before? How did you resolve it?
A possible maven project pom dependency solution is available in this answer.
You can get tibjms-4.1 from pom uploaded in openmindonline repo which has TibjmsQueueConnectionFactory. We are not able to access other version from icm.
Add openmindonline repo information in your repositories block in your build.gradle
repositories {
// You can declare any Maven/Ivy/file repository here.
maven {
url "http://repository.openmindonline.it/"
}
}
Then add implementation 'tibco-ems:tibjms:version:4.1' in dependencies block.
If you have jar file available locally, you can follow solutions available in this question.

Gradle artifactory plugin saying "Cannot cast object 'org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention'..."

Here's the configuration to get the artifactory plugin:
buildscript {
repositories {
mavenCentral()
maven { url 'http://jcenter.bintray.com' }
}
dependencies {
classpath group:'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.0.1'
}
}
apply plugin:'com.jfrog.artifactory'
apply plugin:'ivy-publish'
...some publish spec stuff...
I run gradle (2.3) and I get:
> Failed to apply plugin [id 'com.jfrog.artifactory']
> Cannot cast object 'org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention#6b6c7be4' with class 'org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention' to class 'org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention'
Certainly looks like a classpath issue, but I literally have this project and a sibling project using this same set of gradle/artifactory configurations and one works and the other does not. Both are part of the same top level project. Same JDK (1.8.0_20). Same Gradle. Same everything.
I'm baffled...
The problem was that when I added the various bits to the sibling project that meant I had two projects defining the buildscript {} section.
buildscript {
...
dependencies {
classpath group:'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.0.1'
}
}
Apparently that caused two different versions of the dependency to exist in the classpath, hence the error.
The solution was to move the buildscript bit into the master project so those dependencies are only defined once:
buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath group:'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.0.1'
}
}
Here's another potential cause. All of this looks to be a problem with rival classloaders defining the class. The full qualified classes include the loader. so, load A foo.bar is not loader B foo.bar and crossing that divide is a complex dance requiring interfaces and careful definition.
So, when using the Jenkins artifactory plugin to build your gradle project with the gradle artifactory plugin, you must add the usesPlugin or jenkins plugin will generate an init script which adds the gradle plugin on to a class loader.
def server = Artifactory.server "artifactory"
def rtGradle = Artifactory.newGradleBuild()
rtGradle.usesPlugin = true // Artifactory plugin already defined in build script
...
My problem was, desktop build OK, jenkins build shows this post's problem
I was getting a similar exception when building with Jenkins. For me the conflict was with Jenkin's version and the version in the Build script:
To address this the Artifactory section of the build has a flag you can check specifying that you want to use the version from the gradle file:
This fixed my issue. Hope it helps.
I had a similar problem. Gradle seems to try to reach across and do some checking or evaluation across siblings. I have a top level settings.gradle with 10 or so subprojects.
The fix for me was to put the buildscript block and dependencies at the top level build.gradle and put it in each of the individual subprojects build.gradle files where needed.
My guess as to the reason this works is that the plugin gets loaded in the parent which will be a parent classloader, then each child project inherits that classloader such that the declaration in the lower child script uses that classloaders class and CCE does not occur. The problem is they are the same class, but not assignable since the different classloaders per subproject if nothing is declared at the top. This was Gradle 2.4, and using IntelliJ 14.
In case it helps someone, I got the same error, but for a different reason.
I had the following in my build.gradle:
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:+"
}
At some point the artifactory plugin updated itself from version 3.x to version 4.x while building, because no specific version was specified for the dependency. After it updated I got the error (Could not find any convention object of type ArtifactoryPluginConvention).
I guess the problem was that the rest of the configuration in my build script doesn't work with the new plugin version. Setting the dependency to use version 3.x fixed the problem for me:
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.+"
}
While the currently accepted answer correctly identifies the cause of this issue, the proposed solution doesn't work when you still need to be able to build individual subprojects (because then of course they no longer have access to the buildscript defined repositories and dependencies). The solution that worked for me was to have identical buildscript blocks in each of my subprojects, that seemed to be the key. Any variations would cause the original error.
I got the same exception thrown by bamboo:
'org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention#18eb2827' with class 'org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention' to class 'org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention'
Since the bamboo Bamboo Artifactory Plugin by default looks for the gradle.propeties file in each sub-project module, it has to be provided there.
There is no need for publishing logic in the build.gradle file since the Bamboo Artifactory plugin will read the gradle.properties file for each module respectively, containing:
group=com.example
artifactId=your-project
version=1.0.0
The reason that I got the ArtifactoryPluginConvention exception thrown was that my configured build plan on Bamboo was misconfigured.
With misconfigured, the build ordered of the tasks was not correct. Have a look at your bamboo building tasks/preferably clone a Bamboo plan that is already working.

How to define repositories for all subprojects in Gradle

I am writing Gradle scripts to build a lot of projects. They are using the same repositories so I would like to define repositories for all of my sub-projects instead of defining in each of them.
So I try to move the repositories definition from the build.gradle in an individual project into the build.gradle in their parent folder.
subprojects{
repositories{
mavenCentral()
flatDir{
name 'uploadRepository'
dirs '../../sharedlib'
}
}
}
However, the sub-projects can't find the repository definition at all. Moving other configurations in subprojects closure work. I've tried dependencies and properties configuration. They all work with no problem. I don't know why repositories work differently.
When Googling, I can't find any example of putting repositories inside subprojects, I suspect I am doing it the wrong way. Please tell me what's wrong.
Thanks!
I finally figured out what the problem was.
Originally, I missed the settings.gradle in the parent folder. (I don't know why dependencies configuration works even without this file)
After I put that in, the sub-projects could find the repositories, but the dependencies and an one property (sourceCompatibility=1.5) I defined in the parent project no longer works.
I have to move the apply plugin:'war' from the subproject's build.gradle to the parent's subprojects{...}
I figure that's because the dependencies and sourceCompatibility are things provided by the plugin. And somehow Gradle doesn't look into the subproject's script to find the plugin first.
Your repository declarations look fine, except that an upload repository isn't declared in the project.repositories block but inside the upload task (e.g. uploadArchives). The Gradle User Guide has the details.

Filter dependency lookup for Repository in Gradle

I have defined 2 Repos in my Gradle build:
repositories {
mavenLocal()
maven { url "http://someurl:8081/nexus/content/repositories/myrepo" }
}
Now I just want to resolve specific artifacts (my project-internal groupId) via mavenLocal, all other dependencies shoud get looked up via the maven repo.
My Idea was to do something like
mavenLocal{
addFilter('group') {artifact, file ->
artifact.group == 'my.group'
}
}
but it's not working. Is there a way to intercept dependency lookup for the local maven repository?
Note: I've seen How to configure gradle to use a local repository only for certain dependency groups? , but the solution provided is not satisfactory for me.
As discussed here: http://forums.gradle.org/gradle/topics/problem_mixing_gradle_and_maven_repositories I need the maven local repo to interchange between maven and gradle builds
EDIT: According to Peter Niederwisers Answer, "There isn't currently a finer-grained way to control this." (Current version: 1.5)
an update to who is out on as of gradle 5.1+: we now have (incubating) Declaring a repository filter
repositories {
mavenLocal{
content {
includeGroup "my.group"
}
}
}
A dependency is searched for in all repositories, in the repositories' declared order. The search stops once the dependency has been successfully resolved. There isn't currently a finer-grained way to control this.
If you absolutely need a workaround, you could try to come up with a solution based on spreading dependency declarations over multiple projects (which can have different repositories).

Adding jars to classpath using gradle

In gradle, is there a way to reference external jars. I have some external jars, sitting in another folder outside the project structure. Is there a way to add a reference to these jars in my build.gradle file, so that they are picked up during the compilation process?
Thanks
Edit:
I modified mu build.gradle with an allprojects task having the following 'sub-tasks(?)' as follows:
repositories{
flatDir name:'ExternalJars',dirs:'<path to the jars>'
dependencies{
compile: 'jarname:jarname:version'
}
}
This seems to make my build run just fine. Can someone shed some light on what exactly is happenning when I create the repository and specify the dependencies? - Thanks
The basic idea is that it looks for jar files in the root directory(s) you specified in flatDir that match [artifact]-[version].[ext] pattern.
Note: artifact group is ignored (so you can specify them as :jarname:version), and also all artifacts assumed to have no transitive dependencies.
By the way, another way to reference local jars is to create a local ivy repository. You'll need to use this if you want to declare transitive dependencies.

Resources