clone git repository on my gradle using Grgit - java

I have a gradle project which runs a script, and somewhere in it, I need to clone a git repository.
I had it running before with svn, but I change our company SCM to gitlab, and I need to change the code so it'll now clone the repo from git.
I need something that will work similar to this SVN code:
task exportLibs(type: SvnExport) {
svnUrl = "http://<svn-url>"
targetDir = "<target-dir-to-download-files>"
}
So I read about Grgit, but there was not a single example online, how to do a simple git clone (only this link http://ajoberstar.org/grgit/docs/groovydoc/org/ajoberstar/grgit/operation/CloneOp.html). If there is someone who can help me walkthrough this problem or maybe produced me to his grgit project so i will learn from it, it'll be awesome!
--Edit--
when i tried to use the grgit as below:
group 'test'
version '1.0-SNAPSHOT'
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.ajoberstar:gradle-git:1.7.2"
}
}
apply plugin: 'java'
apply plugin: 'org.ajoberstar.grgit'
org.ajoberstar.grgit.auth.hardcoded.allow=true
task pullFromGit{
doLast {
//grgit.pull()
}
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
i've use this properties to initial it, and i got the following error:
A problem occurred evaluating root project 'grgit'.
Could not get unknown property 'org' for root project 'grgit' of type org.gradle.api.Project.

There is a link on the github page of the project to some examples and the API documentation. The following snippet would solve your problem (in this case, it will clone the grgit project to the grgit directory)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.ajoberstar:grgit:1.7.2'
}
}
task hello {
doLast {
org.ajoberstar.grgit.Grgit.clone(dir: 'grgit', uri: 'https://github.com/ajoberstar/grgit.git')
}
}
Answer to the edited question
The documentation states that org.ajoberstar.grgit.auth.hardcoded.allow is a system property. Your assignment is not a valid way to set system properties, see the answer to this question for examples on setting system properties in groovy.

my code probably had some special imports in it, cause a the end the only clone that i could have done is shell exec.
the problem is solved, but not the bug i had...

Related

Add parameter to a Gradle plugin

I'm new to Gradle and I'm working on a Liferay project. I'm trying to use the Liferay javadoc gradle plugin without success. I'm working on the Liferay IDE (Eclipse) and I already have the javadoc task available to execute. The problem is, after the excution (which completes successfully) I can't find the created docs.
I read the documentation which says there is destinationDir property but I'm unable to set it using Gradle.
I tried following this SO question in order to create a custom Gradle task but without success.
How can I set the destinationDir in order to get the generated docs?
Edit:
The (automatic generated) settings.gradle is:
buildscript {
dependencies {
classpath group: "com.liferay", name: "com.liferay.gradle.plugins.workspace", version: "1.5.0"
classpath group: "net.saliman", name: "gradle-properties-plugin", version: "1.4.6"
}
repositories {
maven {
url "https://cdn.lfrs.sl/repository.liferay.com/nexus/content/groups/public"
}
}
}
apply plugin: "net.saliman.properties"
apply plugin: "com.liferay.workspace"
I'm pretty sure that com.liferay.gradle.plugins.workspace includes the javadoc plugin. Furthermore, Liferay also automatically creates an empty build.gradle where I put:
apply plugin: 'java'
task api(type: Javadoc) {
source = sourceSets.main.allJava
destinationDir = new File(buildDir, "/api")
}
Launching the api Gradle task the javadoc plugin is not executed

groovy.lang.MissingPropertyException: Could not set unknown property 'versionKey' for project ':flamingo' of type org.gradle.api.Project

I have this error while trying to compile the flamingo graphic tools for java, using intelliJ.
here is the build.gradle file for the error's project :
import javax.swing.SwingUtilities
dependencies {
compile project(":trident")
compile group: 'org.tmatesoft.svnkit', name: 'svnkit', version:'1.2.3.5521'
compile group:'org.apache.xmlgraphics', name:'batik-swing', version:'1.7'
compile (group:'org.apache.xmlgraphics', name:'batik-transcoder', version:'1.7') {
exclude group:'xml-apis'
exclude group:'xalan'
exclude group:'commons-io'
exclude group:'commons-logging'
exclude group:'org.apache.avalon.framework'
}
testCompile group: 'com.jgoodies', name: 'forms', version: '1.2.0'
testCompile group: 'junit', name: 'junit', version: '4.3.1'
testCompile group: 'org.easytesting', name: 'fest-assert', version: '1.2'
testCompile group: 'org.easytesting', name: 'fest-reflect', version: '1.2'
testCompile group: 'org.easytesting', name: 'fest-swing', version: '1.2.1'
testCompile group: 'org.easytesting', name: 'fest-swing-junit', version: '1.2.1'
testCompile group: 'org.easytesting', name: 'fest-swing-junit-4.3.1', version: '1.2.1'
}
sourceSets {
main
test
}
test {
// if we are headless, don't run our tests
enabled = !Boolean.getBoolean("java.awt.headless")
}
jar {
manifest {
attributes(
"Flamingo-Version": version,
"Flamingo-VersionName": versionKey,
)
}
}
task testJar(type: Jar) {
classifier = 'tst'
from sourceSets.test.classes
manifest {
attributes(
"Flamingo-Version": version,
"Flamingo-VersionName": versionKey,
)
}
}
uploadArchives {
try {
def x = [deployUsername, deployPassword]
} catch (Exception e) {
deployUsername = 'unset'
deployPassword = ''
}
repositories {
mavenDeployer {
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication userName: deployUsername, password: deployPassword
}
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication userName: deployUsername, password: deployPassword
}
configurePOM(pom)
}
}
}
install {
configurePOM(repositories.mavenInstaller.pom)
}
private def configurePOM(def pom) {
configureBasePom(pom)
pom.project {
name "flamingo"
description "A fork of #kirilcool's flamingo project"
url "http://insubstantial.github.com/peacock"
}
// deal with a gradle bug where transitive=false is not passed into the generated POM
pom.whenConfigured {cpom ->
cpom.dependencies.each {it
switch (it.artifactId) {
case 'trident':
it.classifier = 'swing'
break
}
}
}
}
I don't know what to add for the version key, nor where.
The project is on GitHub : it's a fork of the original project flamingo.
Here is the build.gradle file inside the root directory:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'de.huxhorn.gradle:de.huxhorn.gradle.pgp-plugin:0.0.3'
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'maven'
try {
def test = pgpSecretKeyRingFile // exception will throw if not set
apply plugin: 'sign'
apply plugin: de.huxhorn.gradle.pgp.PgpPlugin
} catch (Exception ignore) {}
group = 'com.github.insubstantial'
version = '6.3-SNAPSHOT'
versionKey = "6.3-defender"
release = "internal"
sourceCompatibility = 1.6
targetCompatibility = 1.6
configurations {
maven { extendsFrom archives }
}
repositories {
mavenRepo urls: 'https://oss.sonatype.org/content/groups/staging'
mavenCentral()
mavenRepo urls: new File(System.getProperty('user.home'), '.m2/repository').toURI().toString()
}
task sourceJar(type: Jar) {
from sourceSets.main.java
from sourceSets.main.resources
classifier = 'sources'
}
task javadocJar(type: Jar) {
dependsOn javadoc
from javadoc.destinationDir
classifier = 'javadoc'
}
artifacts {
maven sourceJar
maven javadocJar
}
uploadArchives {
try {
def x = [deployUsername, deployPassword]
} catch (Exception e) {
deployUsername = 'unset'
deployPassword = ''
}
configuration = configurations.maven
repositories {
mavenDeployer {
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication userName: deployUsername, password: deployPassword
}
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication userName: deployUsername, password: deployPassword
}
}
}
}
install {
configuration = configurations.maven
}
configureBasePom = { pom ->
pom.project {
modelVersion '4.0.0'
packaging 'jar'
scm {
connection 'scm:git:git#github.com:Insubstantial/insubstantial.git'
developerConnection 'scm:git:git#github.com:Insubstantial/insubstantial.git'
url 'scm:git:git#github.com:Insubstantial/insubstantial.git'
}
developers {
developer {
name 'Kirill Grouchnikov'
email 'kirillcool#yahoo.com'
roles {
role 'author'
role 'developer'
}
}
developer {
name 'Danno Ferrin'
email 'danno.ferrin#shemnon.com'
roles {
role 'maintainer'
}
}
}
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '1.0-milestone-2'
}
moreover, the main build.gradle contains the word "Exception" which raise an error from intelliJ.
Well, your main problem is that - and both of these are valid statements, you can select for yourself which you find more appealing - the project is designed for a too old Gradle version for usage with a current Gradle integration and / or your IntelliJ version (or rather its Gradle integration) is too new for usage with that project.
To be more technically precise, the IDE Gradle plugins use the Gradle Tooling API to interact with the Gradle build (run it, get information about source paths, dependencies, tasks, ...). The current version of the Tooling API that is used in the IDE plugins is compatible with builds down to Gradle 1.2 which is really quite ancient already. Your build though is designed for being run with Gradle 1.0-milestone-2 - which is not even a productive release - and defines this in its Gradle wrapper settings.
This means, that if you run Gradle from the commandline, 1.0-milestone-2 is used automatically and the build is working as designed (that's the cool magic of the wrapper). If you try to import the project with the Gradle integration of IntelliJ and tell it to use the projects default wrapper (the default choice and always the best idea and if a project does not use the wrapper, tell them to add it), IntelliJ tells you The project is using an unsupported version of Gradle. Please point to a supported Gradle version in the project's Gradle settings or in the project's Gradle wrapper (if applicable.). I guess you then discarded the message dialog and told IntelliJ to use some local Gradle installation instead and then you get the error you mentioned. (Btw. you should have mentioned that you followed this way, makes helping much easier)
When there are major version bumps in Gradle version, they remove stuff they deprecated long enough before according to their deprecation and removal policy and builds might break with these changes which is exactly what you are exhibiting, as you use a Gradle version that this build is not designed for and is not compatible with.
So what you can do is two things.
Either you do not use the Gradle integration in IntelliJ with this project but use Gradle only from the commandline. You can add allprojects { apply plugin: 'idea' } to your build.gradle and then use ./gradlew idea to generate properly configured IntelliJ project files that you then can open with IntelliJ and work with the project.
The other option - and I would really recommend it, even if it is more work - is to update the build to be compatible with current Gradle versions and configure the wrapper to use that new version, then the integration works flawlessly and you also benefit from all development that was done in Gradle since that really old version. You can read the release notes for important changes and breaking changes and interesting changes. To just get it done it should also be sufficient to update to the latest 1.x version, fix all deprecated warnings, update to the latest 2.x version, fix all deprecated warnings, update to the latest 3.x version, fix all deprecated warnings and then update to the latest 4.x version. This should at least make the build working with the latest version in a guided way, even though the build might not be the best one, not using some of the new things that were added to Gradle in the meantime. But this could at least be used as a starter.
You might be tempted to think you can also do a middle-thing and just set the wrapper to use 1.2. As it is in the same major version, the build should work with it and as I said before, 1.2 is currently the oldest version that is working with the integration. At least partly. Things like cancelling a build will e. g. not work as 1.2 does not yet support this, even if the tooling API does. But this won't work, because the build as it is does not even with 1.0. As 1.0-milestone-2 was only a pre-release, there the stability guarantees of course did not hold yet and there was a change between that and 1.0 that breaks your build.
Regarding the actual two errors you got, the first, the one with the unknown property is exactly one of the breaking changes I mentioned. Previously you could simply set any new property by doing foo = 'value'. The problem is, that people often mistyped properties, e. g. wrote fop = 'value' instead and then wondered why it doesn't work, not getting any helpful error message. So dynamically defined properties were forbidden and you have to do it in the ext namespace like ext { foo = 'value' } or ext.foo = 'value', but only on the first occurrence. This defines the new custom property and later on you can get and set it only by its name. If it shouldn't have been a property of the object in question (the project in your case) in the first place, but just a local variable in the build script, it should simply be defined as local variable like def foo = 'value' like always in Groovy which Gradle is based on.
Regarding the second error, the Exceptions IntelliJ is complaining about. Mine does not complain at all, I don't know what inspections you maybe have enabled or whatever, but if it is ok for Gradle it should be ok for IntelliJ if it is not, you should report it as bug to JetBrains, but as I said, here it is not red. But using exceptions for flow control like in that build script is very bad practice anyway, not only in build scripts, but in Java or even in programming at all.
try {
def test = pgpSecretKeyRingFile // exception will throw if not set
apply plugin: 'sign'
apply plugin: de.huxhorn.gradle.pgp.PgpPlugin
} catch (Exception ignore) {}
could e. g. be written like
if (project.hasProperty('pgpSecretKeyRingFile')) {
apply plugin: 'sign'
apply plugin: de.huxhorn.gradle.pgp.PgpPlugin
}
and
try {
def x = [deployUsername, deployPassword]
} catch (Exception e) {
deployUsername = 'unset'
deployPassword = ''
}
could e. g. be written like
if (!(project.hasProperty('deployUsername') && project.hasProperty('deployPassword'))) {
deployUsername = 'unset'
deployPassword = ''
}
without changing the meaning of the code

Cannot import when using Eclipse and Gradle

I am working on a java project which uses Gradle to build. I wanted to use the Eclipse WindowBuilder to help with the GUI work, so I used the Gradle Eclipse plugin, generated the Eclipse files, and imported it into Eclipse.
The problem is that none of my imports are resolving. The project builds fine using Gradle, but Eclipse can't import anything for my project. How do I solve this?
I don't know which files to include to help debug this, so if something might help let me know and I will include it.
Thanks in advance for your help!
EDIT: Here is my build.gradle file:
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
buildscript {
def rosMavenPath = "$System.env.ROS_MAVEN_PATH".split(':').collect { 'file://' + it }
def rosMavenRepository = "$System.env.ROS_MAVEN_REPOSITORY"
repositories {
rosMavenPath.each { p ->
maven {
url p
}
}
mavenLocal()
maven {
url rosMavenRepository
}
}
dependencies {
classpath group: 'org.ros.rosjava_bootstrap', name: 'gradle_plugins', version: '[0.1,0.2)'
}
}
apply plugin: 'catkin'
apply plugin: 'eclipse'
allprojects {
/*
A github url provides a good standard unique name for your project
Example below, but you may wish to switch to your own unique url.
*/
group 'com.github.rosjava.gui_test'
version = project.catkin.pkg.version
}
subprojects {
/*
See https://github.com/rosjava/rosjava_bootstrap (look for gradle_plugins)
to see what is going on under the hood.
*/
apply plugin: 'ros-java'
}

How to use code from a project in a maven repository

I am trying to use code from this project: https://github.com/gabrielemariotti/cardslib, and I am trying to do this with intelij. In the instructions provided with the library it simply says to add this to build.gradle file:
dependencies {
compile 'com.github.gabrielemariotti.cards:library:1.3.0'
}
however when I add this and try to use code from the project intelij gives errors such as unable to resolve symbol, etc. So I am wondering what are the other steps needed to use code from this project that must be done using intelij. Any help is appreciated.
My build.gradle file currently looks like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/GoogleAdMobAds.jar')
compile files('libs/libGoogleAnalyticsV2')
compile files('libs/amazon-ads-5.1.10.jar')
compile project('libraries/cardslib/library')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 16
}
}
dependencies {
// Cards Library
compile 'com.github.gabrielemariotti.cards:library:0.6.0'
compile project(':libraries:cardslib:library')
}
The documents here are also helpful to new Maven users.
Download and Install Maven - Download the latest version of Maven and install it
Quick Start - Get started building the project quickly
Use Maven - Learn how to use Maven on your own project
Refer this the below link to get much more details...
http://maven.apache.org/run-maven/
You need to add the maven central repository to your build file.
The simplest way is to just put this in your build.gradle directly under apply plugin: 'android':
repositories {
mavenCentral()
}
Resync your IDE with the gradle file after doing so.
It should resolve the dependency like any other maven central dependency (e.g. ABS).
If you are using sources (git repo cloned) at rootProject/libraries/cardslib, then add its library in rootProject/settings.gradle:
include ':appModule', ':libraries:cardslib:library'
and then in rootProject/appModule/build.gradle:
dependencies {
compile project(':libraries:cardslib:library')
}
Or, if you use maven, then just do this in rootProject/appModule/build.gradle:
dependencies {
compile 'com.github.gabrielemariotti.cards:library:1.3.0'
}
so the library's jar/aar will be downloaded in ~/.gradle/caches/modules-2/... and be compiled.
Pick one of above, don't do both.

how to create Google App Engine Project with Gradle

A I'm new to Google App Engine and even I have Spring tool suite with gradle plugin installed, I facing difficulty . I want to know what the process ,how to implement ,if any sample basic project to implement can anybody help me .Even I have Goggled but getting get the doc and but when I'm trying to implement getting errors,unable to create a sample project any suggestion with code is appreciated
Thanks in advance....
Here is my setup for the appengine guestbook sample
https://developers.google.com/appengine/docs/java/gettingstarted/introduction
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.4'
}
}
apply plugin: 'war'
apply plugin: 'appengine'
sourceCompatibility = 1.7
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
providedCompile 'javax.servlet:servlet-api:2.5'
compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.4'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
appengine {
httpPort = 8085
appcfg {
email = 'you#gmail.com'
passIn = true
logs {
severity = 1
outputFile = file('mylogs.txt')
}
app {
id = 'guestbook'
}
}
}
gradle.properties (in project root)
systemProp.appengine.sdk.root = /Users/<me>/Documents/appengine-java-sdk-1.9.4
Create a webapp directory in your project's "src/main" folder and copy the files from the sample webapp directory there.
I'd check out the docs for Google's offical Gradle AppEngine plugin, which also has a small example. SpringSource Tool Suite is irrelevant here. If you hit any problems, post a concrete question that explains the problem in detail, along with all output you get.

Categories

Resources