Resolving transitive dependencies from Artifactory in gradle - jenkins

My project has two modules, lib and lib-api, with the following responsibilities
lib-api - a pure java module that only contains interface files
lib - an android library
and I'd like to jenkins publish both modules (as jars) to an internal artifactory server for other projects to be able consume.
Using the Jenkins Artifactory Plugin, I was able to publish jars for both modules to artifactory, but my other project that depends on lib fails to build with the following gradle error
Could not find com.mygroup:lib-api:1.0.0-SNAPSHOT
My setup
Build scripts
lib-api/build.gradle
apply plugin: 'java'
apply plugin: 'maven-publish'
group = 'com.mygroup'
version = project.version
publishing {
publications {
api(MavenPublication) {
from components.java
}
}
}
lib/build.gradle
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
android { ... }
dependencies {
compile project(':lib-api')
}
group = 'com.mygroup'
version = project.version
Jenkins Artifactory plugin config
Gradle-Artifactory Integration
Publish artifacts to Artifactory
Publish Maven descriptors
Use Maven compatible patterns
Invoke Gradle script
Use Gradle Wrapper
Tasks: clean assemble -x preDexDebug -x preDexDAT -x preDexRelease
Result in Artifactory repo
+-- libs-snapshot-local
| +-- com
| | +-- mygroup
| | | +-- lib
| | | | +-- 1.0.0-SNAPSHOT
| | | | | `-- lib-1.0.0-20150508-1.jar
| | | | | `-- lib-1.0.0-20150508-1.pom
| | | | | `-- maven-metadata.xml
| | | | `-- maven-metadata.xml
| | | +-- lib-api
| | | | +-- 1.0.0-SNAPSHOT
| | | | | `-- lib-1.0.0-20150508-1.jar
Question
My understanding is that artifactory/gradle should be smart enough to resolve -SNAPSHOT into the latest timestamped snapshot and that seems to be borne out by the fact that it manages to resolve lib whether I specify latest.integration or 1.0.0-SNAPSHOT
How can I get gradle to resolve this transitive snapshot dependency from artifactory? Or get the artifactory plugin to publish the jar in such a way that gradle can resolve it?
Working theory
I noticed that the lib-api folder doesn't have a maven-metadata.xml file and the snapshot version folder doesn't have one either... or pom file. I suspect this might be the issue.
Artifactory's Jenkins plugin uses the gradle artifactory plugin under the hood for jobs that have Gradle-Artifactory integration enabled. According to the gradle artifactory plugin docs the plugin ID changes depending on whether you are using the new (maven-publish) or old (maven) publishing mechanism.
Could this be the issue? Is the Artifactory plugin applying the wrong plugin ID, perhaps because it is making it's decision based on the android library module?

tl;dr Switching to the old maven plugin for gradle fixed it.
My lib-api/build.gradle now looks like this
apply plugin: 'java'
apply plugin: 'maven'
group = 'com.mygroup'
version = project.version
ext.artifactId = project.name.toLowerCase()
project.archivesBaseName = project.artifactId
uploadArchives {
repositories {
mavenDeployer {
pom.artifactId = project.artifactId
}
}
}
Note: According to the gradle docs for the maven plugin, pom.artifactId must be explicitly defined if you've set archivesBaseName. That may have been the underlying issue with my previous configuration, but I did not go back and test it.

Related

indirect jar conflict between spring-security-rest and guava causing NoSuchMethod error

I use grails 3.1.16
build.gradle:
dependencies {
compile "com.google.guava:guava:18.0"
compile "org.grails.plugins:spring-security-rest:2.0.0.M2"
}
while running this code:
private LoadingCache<String, Boolean> attempts
#PostConstruct
void init() {
Integer time = ApplicationContextHolder.getProperty(ApplicationContextHolder.config.time)
attempts = CacheBuilder.newBuilder()
.expireAfterWrite(time, TimeUnit.MINUTES)
.build({ 0 } as CacheLoader)
}
I am getting the following errors:
Caused by: java.lang.NoSuchMethodError: com.google.common.base.Platform.systemNanoTime()J
at com.google.common.base.LocalCache(Ticker.java:60)
at com.google.common.cache.LocalCache$Segment.put(LocalCache.java:2827)
at com.google.common.cache.LocalCache.put(LocalCache.java:4149)
at com.google.common.cache.LocalCache$LocalManualCache.put(LocalCache.java:4754)
at com.google.common.cache.Cache$put.call(Unknown Source)
After running dependency-report, I found out that the issue was caused by a dependency of the Spring Security REST Plugin: ( com.google.guava:guava-base:r03) - with the same package name "com.google.common.base" and Platform.class with no such method systemNanoTime()
| +--- org.grails.plugins:spring-security-rest:2.0.0.M2
| | +--- com.google.guava:guava-io:r03
| | | +--- com.google.guava:guava-annotations:r03
| | | \--- com.google.guava:guava-base:r03
| | | \--- com.google.guava:guava-annotations:r03
Any ideas to solve this ?
Step 1. Please check with updated dependencies(issue may be reported):
dependencies {
compile 'org.grails.plugins:spring-security-rest:2.0.0.RC1'
compile 'com.google.guava:guava:24.0-jre'
}
You can check spring-security-rest documentation and repo
and for guava documentation and repo
OR
Step 2.
compile("org.grails.plugins:spring-security-rest:2.0.0.RC1") {
excludes([group: 'com.google.guava:guava'])
}
OR
Step 3. in your build.gradle you can exclude the compiled classes from the JAR file:
jar {
exclude "com/google/guava/**/**"
}
or you can refer grails documentation
Have you tried?
dependencies {
compile "com.google.guava:guava:18.0"
compile ("org.grails.plugins:spring-security-rest:2.0.0.M2") {
exclude module: 'guava-base'
// can also be specified with group
// exclude group: 'com.google.guava', module: 'guava-base'
}
}
This will exclude the transitive dependency of guava-base from spring-security-rest.

Grails V2.3.7 starts up application automatically during test-app functional:

I recently upgraded Grails to V2.3.7 and noticed that when I ran grails test-app functional: the application would be started up automatically like so:
:grails-test-app-functional
| Loading Grails 2.3.7
| Configuring classpath
| Running pre-compiled script
| Running pre-compiled script.
| Environment set to test
| Environment set to test.
| Environment set to test..
| Environment set to test...
| Environment set to test....
| Environment set to test.....
| Compiling 1 source files
| Compiling 1 source files.
| Compiling 1 source files..
| Compiling 1 source files...
| Compiling 1 source files....
| Compiling 1 source files.....
| Running Grails application
Configuring Spring Security Core ...
... finished configuring Spring Security Core
| Server running. Browse to http://localhost:8080/myApplication
This did not happen in V2.3.6. My questions are:
1) Is this new in V2.3.7 or did I configure something unknowingly?
2) How do I disable this auto running of the app?
Thanks.
The app has to be started in order to run your functional tests. The functional tests interact with the running app. This has always been the case.

Grails 2.0.4/2.1.1 test-app throws ClassNotFoundException (GrailsSpecTestType)

I have a legacy grails appliction that I recentyl upgraded 1.3.7 -> 2.0.4
The same thing happens after I upgrade it to 2.1.1
When I try to run test-app from GGTS I get:
| Error Error executing script TestApp: java.lang.ClassNotFoundException: grails.plugin.spock.test.GrailsSpecTestType (Use --stacktrace to see the full trace)
There is a similiar report from April on SS site.
I also see there are a lot of questions about similiar exceptions for grails 1.3.7 -- this however is a problem affecting 2.0.4.
EDIT: OK, it actually happens in command line too, but at least I can get it to work.
Unfortunately after a restart it breaks again.
Here is what I do to fix it in console, basically I upgrade to 0.7 and the downgrade to 0.5-groovy-1.7
grails> clean
| Application cleaned.
grails> refresh-dependencies
| Dependencies refreshed.
grails> test-app
| Compiling 73 source files
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
| Compiling 119 source files
| Compiling 119 source files.
| Error Error running script test-app : java.lang.ClassNotFoundException: grails.plugin.spock.test.GrailsSpecTestType (U
se --stacktrace to see the full trace)
grails> install-plugin spock
| Resolving plugin spock. Please wait...
> You currently already have a version of the plugin installed [spock-0.5-groovy-1.7]. Do you want to update to [spock-0
.7]? [y,n] y
| Plugin installed.
grails> clean
| Application cleaned.
grails> refresh-dependencies
| Application cleaned.....
> You currently already have a version of the plugin installed [spock-0.7]. Do you want to update to [spock-0.5-groovy-1
.7]? [y,n] n
| Dependencies refreshed.
grails> test-app
> You currently already have a version of the plugin installed [spock-0.7]. Do you want to update to [spock-0.5-groovy-1
.7]? [y,n] n
| Compiling 73 source files
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
| Compiling 119 source files
| Compiling 119 source files.
| Error Error running script test-app : java.lang.ClassNotFoundException: grails.plugin.spock.test.GrailsSpecTestType (U
se --stacktrace to see the full trace)
grails> install-plugin spock
| Plugin 'spock' with version '0.7' is already installed
| Plugin not installed.
grails> uninstall-plugin spock
| Uninstalled plugin [spock]
grails> clean
| Application cleaned.
grails> refresh-dependencies
| Dependencies refreshed.
grails> test-app
| Compiling 73 source files
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
| Compiling 119 source files
| Running 8 unit tests... 5 of 8
So this is apparently caused by some misbehaving plugin exporting it's spock dependency.
Sample workaround if your troublemaker is GWT:
compile(':gwt:0.8') {
exclude 'spock'
}
Thanks to Nathan Dunn

Grails Release plugin is not deploying plugin on a remote maven repository

I'm having problems to deploy a plugin with the command maven-deploy on a remote repo.
I installed the latest version of the Release plugin (2.0.2).
I get this error:
| Loading Grails 2.0.4
| Configuring classpath.
| Environment set to development.....
| Packaging Grails application.....
| Compiling 33 GSP files for package [myPackage].....
| Plugin packaged grails-plugin-myPlugin.jar
| Skipping POM generation because 'pom.xml' exists in the root of the project..
| Error Error executing script MavenDeploy: : Error downloading wagon provider from the remote repository: Missing:
----------
1) org.apache.maven.wagon:wagon-http:jar:1.0-beta-2
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=org.apache.maven.wagon -DartifactId=wagon-http -Dversion=1.0-beta-2 -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=org.apache.maven.wagon -DartifactId=wagon-http -Dversion=1.0-beta-2 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Path to dependency:
1) unspecified:unspecified:jar:0.0
2) org.apache.maven.wagon:wagon-http:jar:1.0-beta-2
----------
1 required artifact is missing.
for artifact:
unspecified:unspecified:jar:0.0
from the specified remote repositories:
central (http://repo1.maven.org/maven2)
(Use --stacktrace to see the full trace)
Thanks for your help
I had the same problem and could handle it this way:
Install Maven2
Configure proxy as described here
This is enough to solve your problem.
If your maven server requires authentication you can proceed as described here or here
~/.m2/settings.xml:
<settings>
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>proxyserver.mydomain.com</host>
<port>8080</port>
<username>user</username>
<password>pass</password>
<nonProxyHosts>*.bla.com.br|*.blabla.biz</nonProxyHosts>
</proxy>
</proxies>
<servers>
<server>
<id>myrepo</id>
<username>user</username>
<password>pass</password>
</server>
</servers>
</settings>
This looks like a Maven issue:
Maven fails to download a required dependency
org.apache.maven.wagon:wagon-http:jar:1.0-beta-2 from
http://repo1.maven.org/maven2
Since the required artifact can be found in Maven central this may be a result of a networking issue
I found a workaround for this issue. Since something tries to retrieve wagon-http dependency using deprecated http maven repository url, we can manually preinstall this dependency in our local repository:
mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get -Dartifact=org.apache.maven.wagon:wagon-http:1.0-beta-2 -Dpackaging=jar -DrepoUrl=https://repo1.maven.org/maven2
After that publish-plugin command should work.
Possible fix for that issue would be upgrade grails-release plugin to v3.1.3(didn't work for me): link

Why do I get many repeated compiling messages during a grails build in intelliJ

Here's the build console trace when I launch a grails 2.0 app in intellij in debug mode. It didn't used to be so verbose in grails 1.3.4
"C:\Program Files\Java\jdk1.6.0_22\bin\java" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:57461,suspend=y,server=n -Dgrails.home=C:\grails-2.0.0.M2 -Dbase.dir=C:\apps\myapp "-Dtools.jar=C:\Program Files\Java\jdk1.6.0_22\lib\tools.jar" -Dgroovy.starter.conf=C:\grails-2.0.0.M2/conf/groovy-starter.conf -Xmx1G -Xms356m -XX:MaxPermSize=356m -javaagent:C:\Users\aressler\.IntelliJIdea10\system\groovyHotSwap\gragent.jar -Dfile.encoding=windows-1252 -classpath "C:\grails-2.0.0.M2\lib\org.codehaus.groovy\groovy-all\jars\groovy-all-1.8.2.jar;C:\grails-2.0.0.M2\dist\grails-bootstrap-2.0.0.M2.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 10.5.2\lib\idea_rt.jar" org.codehaus.groovy.grails.cli.support.GrailsStarter --main org.codehaus.groovy.grails.cli.GrailsScriptRunner --conf C:\grails-2.0.0.M2/conf/groovy-starter.conf "-Dserver.port=80 run-app"
Connected to the target VM, address: '127.0.0.1:57461', transport: 'socket'
| Loading Grails 2.0.0.M2
| Configuring classpath
| Configuring classpath.
| Environment set to development
| Environment set to development.
| Environment set to development..
| Environment set to development...
| Environment set to development....
| Environment set to development.....
| Packaging Grails application
| Packaging Grails application.
| Packaging Grails application..
| Compiling 3 source files
| Compiling 3 source files.
| Compiling 3 source files..
| Compiling 1 source files
| Compiling 1 source files.
| Compiling 1 source files..
| Compiling 1 source files...
| Compiling 1 source files....
| Compiling 1 source files.....
| Running Grails application
This is on a build where I had made no changes from the last restart. Am I wasting lots of time on each restart with it doing wasted extra packaging and compiling?
Grails 2 is not doing any more work. The reason for the repeated lines is that the new Grails 2 console is telling you that it is still working and progress is being made by adding a new period at the end of the current message.
When working in IntelliJ with Grails 2 I use --verbose and --plain-output to get legacy style logging. The Grails 2 console uses JLine for a more rich command line experience but the IntelliJ console isn't exactly comparable. I throw on --stacktrace for good measure as well when using IntelliJ.
I've created request in IntelliJ tracker to make -plain-output option by default.

Resources