Как я могу добавить подпроекты Gradle в качестве зависимостей к пути к классу задач Ant? - PullRequest
0 голосов
/ 26 сентября 2019

Я работаю над переносом набора сценариев сборки из Ant в Gradle.Это многопроектная сборка, и большинство подпроектов может быть построено исключительно в Gradle.Вот простой сценарий сборки для подпроекта-1:

subproject-1

dependencies {
    api project(':subproject-2')
    api project(':subproject-3')

    api fileTree(dir: 'Libraries', include: '*.jar')

    implementation fileTree(dir: '/more/jars/here/1', include: '**/*.jar')
    implementation fileTree(dir: '/more/jars/here/2', include: '**/*.jar')
    implementation fileTree(dir: '/more/jars/here/3', include: '**/*.jar')
}

Однако для построения конечного приложения требуется использовать уже существующий класс задач Ant.Поэтому мне нужно передать сборку этому классу с помощью Ant и также передать путь к классу Gradle.

Я пытался сделать это с помощью следующего:

основное приложение

// We currently have dependency conflicts.
// We can use an extra configuration to force the correct dependencies to be prioritized
configurations {
    priority
}

dependencies {
    priority project(':subproject-1')

    implementation fileTree(dir: 'Libraries', include: '*.jar')

    implementation fileTree(dir: '/more/jars/here/1', include: '**/*.jar')
    implementation fileTree(dir: '/more/jars/here/2', include: '**/*.jar')
    implementation fileTree(dir: '/more/jars/here/3', include: '**/*.jar')
}

// Force classloader to use priority dependencies first
sourceSets.main.compileClasspath = configurations.priority + sourceSets.main.compileClasspath
sourceSets.main.runtimeClasspath = configurations.priority + sourceSets.main.runtimeClasspath

task specialcompile {
    description 'Special compilation'
    group 'Build'

    ant.taskdef (name: 'specialcompile', classname: 'package.package.package.CompileClass'){
        classpath {
            fileset(dir: '/path/to/compile/class', includes: 'CompileClass.jar')
            configurations.compileClasspath.asPath
        }
    }

    doLast {
        ant.specialcompile(srcdir: 'Sources', destdir: 'build')
    }
}

Однако сборка завершается неудачно, сообщая, что пакеты из подпроекта-1 не существуют.Стоит отметить, что при обычной сборке основного приложения правильно строится стандартное дерево классов Java.Поэтому Gradle знает все, что должно быть в этой сборке, но я не могу передать классы, встроенные в подпроект-1, в Ant.

...