0

i am trying to move my MAVEN build to a gradle therefore i need to solve the following:

project:

  • application (this one shall create a fatjar)

plugins (shall result in single jar files, but no fat jars!)

  • utils (requires: jarX, jarY, jarZ)
  • data (requires: utils, jarX, jarY)
  • controls (requires: data, utils, jarY)

what i worked out is create a jar for each plugin (but i have to FULLY define its dependecies, which is actually gradles job

so what i did was create jar files, copy them manually to a reposiory and declare dependencies on those...

so what i expected is, that i only have to tell application to require controls, because controls already includes anything needed (alsways includes the dependencies from stuff below)

i guess i have to define a project (yes i read the help page of gradle, but i was not able to work it out)

so right now i have settings.gradle in each plugin, but what i read this is wrong. i should only have one settings.gradle in the root.

ROOT: settings.gradle:

include ':application', ':controls', ':data', ':util'

ROOT: build.gradle

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.glazedlists:glazedlists:1.11.0'
        classpath 'org.jooq:jooq:3.12.1'
        classpath 'org.controlsfx:controlsfx:8.40.12'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

and each of the plugins got: build.gradle

plugins {
    id 'java-library'
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

but this does not work either...

thanks in advance

smac89
  • 39,374
  • 15
  • 132
  • 179
lumo
  • 790
  • 1
  • 8
  • 23
  • 3
    The dependencies block of the buildscript block defines the dependencies needed by the build script, i.e. by the gradle tasks themselves. Not the dependencies of your projects. Read https://docs.gradle.org/current/userguide/dependency_management_for_java_projects.html#header (for example), and https://docs.gradle.org/current/userguide/multi_project_builds.html#header – JB Nizet Sep 07 '19 at 15:24
  • What exactly "doesn't work"? What problems are you facing? – smac89 Oct 26 '19 at 09:25
  • It does not resolve the plugins of the included plugins – lumo Oct 26 '19 at 15:39
  • That language is confusing. By your first use of the word "plugin", do you mean [dependencies](https://docs.gradle.org/current/userguide/dependency_management_for_java_projects.html)? By the second use, do you mean [subprojects](https://docs.gradle.org/current/userguide/multi_project_builds.html#sec:subproject_configuration)? i.e. "_gradle is not resolving the **dependencies** of the included **subprojects**_". – smac89 Nov 02 '19 at 01:37
  • i am sorry - i do develop an application (project) which has multiple parts (subprojects, eclipse would call this plugin) - dependencies might be jar files or other parts/subprojects/plugins – lumo Nov 06 '19 at 15:30

1 Answers1

0

Assuming you need to do a multiproject setup, do the following:

settings.gradle

rootProject.name = 'mvn2Gradle'
include ':application', ':controls', ':data', ':util'

build.gradle

allprojects {
    repositories {
        google()
        jcenter()
    }
}

subprojects {
    apply plugin: 'java'

    ext {
        jarYVersion = '1.x'
    }

    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    dependencies {
        implementation "org.example:jarY:$jarYVersion" // Every subproject gets this dependency
    }
}

wrapper { // Run this task once before you start building
    gradleVersion = '5.6.3'
    distributionType = Wrapper.DistributionType.ALL
}

utils: build.gradle

plugins {
    id 'java-library'
}

ext {
    jarXVersion = '1.x'
    jarZVersion = '1.x'
}

dependencies {
    implementation "org.example:jarX:$jarXVersion"
    api "org.example:jarZ:$jarZVersion" // "api" because none of the other projects depends on this jar
}

data: build.gradle

plugins {
    id 'java-library'
}

dependencies {
    implementation project(':utils') // Also inherits "jarX"
}

controls: build.gradle

plugins {
    id 'java-library'
}

dependencies {
    implementation project(':data') // Also inherits "project:utils"
}

application: build.gradle

plugins {
    id 'application'
}

application {
    mainClassName 'my.package.Main'
}

dependencies {
    implementation project(':controls')
}
smac89
  • 39,374
  • 15
  • 132
  • 179