In my Eclipse workspace, I have two projects, projectA and projectB. projectA is in a different folder from projectB (separate git repositories, not near each other on the file system). Is there any way for gradle to apply projectB to the classpath of projectA using the gradle plugin for eclipse?
Project A's build.gradle
apply plugin: 'java'
dependencies {
compile 'myorg:projectB:+'
}
Project B's build.gradle
apply plugin: 'java'
publishing {
publications {
ivy(IvyPublication) {
organisation 'myorg'
module 'projectB'
revision '1.0-SNAPSHOT'
descriptor.status = 'integration'
configurations {
archive {}
}
from components.web
}
}
repositories {
ivy {
url "/path/to/repo"
layout "pattern", {
ivy "[organisation]/[module]/[revision]/[module]-[revision].xml"
artifact "[organisation]/[module]/[revision]/[artifact](-[classifier])-[revision].[ext]"
}
}
}
}
Related
I added the scala plugin to gradle, but i don't how to run it. There's no run task when i create a scala project.
How do I run the scala project?
My gradle build script:
apply plugin: 'idea'
apply plugin: 'scala'
repositories {
mavenLocal()
maven {
url "http://maven.aliyun.com/nexus/content/groups/public/"
}
mavenCentral()
}
dependencies {
compile group: 'org.scala-lang', name: 'scala-library', version: '2.13.1'
}
You need to provide the classpath as well. Change run task declaration to:
task run(type: JavaExec, dependsOn: classes) {
main = 'Demo'
classpath = sourceSets.main.runtimeClasspath
}
And it will work fine. Demo.
I'm having difficulty getting Gradle to add a dependency to my /war/WEB-INF/lib directory in a Google Web Application Project.
apply plugin: 'java'
apply plugin: 'war'
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.code.gson:gson:2.2.4'
}
Using Eclipse, gson-2.2.4.jar shows up in Project and External Dependencies (project compiles) but doesn't get added to /war/WEB-INF/lib (NoClassDef exception at runtime since it can't find the .jar)
I've tried changing webAppDir, webAppDirName, and editing the war task all to no avail.
I'm trying to build a gradle custom plugin that in turn depends on other plugin. In particular, the plugin depends on com.bmuschko.docker-remote-api plugin (that again depends on java library com.github.docker-java:docker-java:2.1.1).
So I tried with the following gradle.build file
apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'com.bmuschko.docker-remote-api'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-docker-plugin:2.6.1'
}
}
group = 'com.example'
version = '1.0'
dependencies {
compile gradleApi()
compile localGroovy()
compile group: 'com.github.docker-java', name: 'docker-java', version: '2.1.1'
}
and the following plugin file:
package com.example.build
import org.gradle.api.Project
import org.gradle.api.Plugin
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
class BndPlugin implements Plugin<Project> {
#Override
void apply(Project project) {
task buildDockerImage(type: DockerBuildImage) {
println file("${projectDir}/docker/")
}
}
}
but what I get with gradle build is just the error
unable to resolve class com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
Question: how to properly manage custom plugin's dependencies?
You can get the full plugin project on github.
If you're going to use classes from the plugin, as opposed to just applying it, you should also include the plugin binaries as compile dependency in your lower dependencies section.
I have a simple gradle file from which I build a jar file.
When I run the jar file however I get and error: 'Exception in thread "main" java.lang.NoClassDefFoundError: scala/Predef$'
The build.gradle looks like this:
apply plugin: 'scala'
apply plugin: 'distribution'
def mainClass = "com.domain.Hello"
distributions {
custom {}
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.scala-lang', name: 'scala-library', version: '2.11.4'
}
jar {
manifest {
attributes 'Main-Class': mainClass
}
}
task run(type: JavaExec, description: "Runs the project") {
main = mainClass
classpath sourceSets.main.runtimeClasspath
classpath configurations.runtime
}
When you run the jar you need to include the scala-library on the classpath, like this
scala -cp [scala library jar] [project jar]
If you don't want to have to do this, take a look at this blog post http://blogs.steeplesoft.com/posts/2013/09/04/building-fat-jars-with-gradle/
You need to include ''scala-compile' package beside 'scala-library'
After some research, I was able to create a non multi project with two projects. Sounds strange? Isn't. It's normal that you don't put all your projects under one root project.
Reading a lot about multi project builds I wondered, why it is so complicated to use one project with another that are not in the same root project.
The only way, that worked for me so fare, is to use Maven publishing.
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
group = 'foo'
version = '0.2.1'
repositories {
mavenCentral()
mavenLocal()
}
jar { baseName = "${project.group}.${project.name}" }
publishing {
publications {
maven(MavenPublication) {
artifactId "${project.name}"
artifact sourceJar { classifier "sources" }
from components.java
}
}
}
task sourceJar(type: Jar) { from sourceSets.main.allJava }
task wrapper(type: Wrapper) { gradleVersion = '1.11' }
Using: gradlew clean build publishToMavenLocal creates two jar libraries (binary and source) at the correct location in the local maven repository .m2
The second project, that depends on the first one has this build.gradle
apply plugin: 'java'
apply plugin: 'eclipse'
group = 'foo2'
version = '0.1'
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
compile("foo:Gradle.test2:0.+")
}
jar { baseName = "${project.group}.${project.name}" }
task wrapper(type: Wrapper) { gradleVersion = '1.11' }
Worked for me. After rebuilding the dependencies I always have the newest version.
Now why do I need the Maven workaround when using Gradle? Can't I publish to the local Gradle cache? What Alternatives are available?
Creating a project dependency without using a common root project is easy once you know how:
In the second project (ProjectTwo), that depends on the first project (ProjectOne), put the following in your settings.gradle file:
include ':ProjectOne'
project(':ProjectOne').projectDir = new File(settingsDir, '../ProjectOne')
The second line above assumes that ProjectOne shares the same parent directory as ProjectTwo, but you can use any relative path to set the correct directory location. Now you can add ProjectOne as a dependency in ProjectTwo's build.gradle file:
dependencies {
compile project(':ProjectOne')
}