在我的Gradle项目中,我有一个SQLite依赖项。
这是我的build.gradle:
import groovy.sql.Sql
buildscript {
ext{
osPackageVersion = "3.4.0"
kotlin_version = '1.2.41'
requery_version = '1.5.1'
sqlite_jdbc = '3.7.2'
rxkotlin_version = '2.2.0'
sqlDirPath = "src" + File.separator + "main" + File.separator + "Resources" + File.separator + "TestAppDbInit.sql"
}
repositories {
mavenCentral()
jcenter()
maven{
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "edu.sc.seis.gradle:launch4j:2.4.4"
classpath group: 'org.jooq', name: 'jooq-meta-extensions', version: '3.11.2'
classpath 'org.jooq:jooq-codegen:3.11.2'
classpath 'org.xerial:sqlite-jdbc:3.7.2'
}
}
plugins {
id 'java'
id 'nu.studer.jooq' version '3.0.1'
}
group 'org.wycliffeassociates.translationrecorder'
apply plugin: 'kotlin'
apply plugin: 'kotlin-kapt'
apply plugin: 'edu.sc.seis.launch4j'
sourceCompatibility = 1.8
configurations {
sqllite
}
repositories {
mavenCentral()
jcenter()
maven { url 'https://jitpack.io'}
maven { url "https://plugins.gradle.org/m2/" }
maven { url 'https://mvnrepository.com/artifac/'}
maven { url "https://dl.bintray.com/kotlin/exposed" }
maven { url "https://dl.bintray.com/dua3/public" }
}
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
dependencies {
compile "no.tornado:tornadofx:1.7.16"
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile "com.github.thomasnield:rxkotlinfx:2.2.2"
compile "io.reactivex.rxjava2:rxkotlin:$rxkotlin_version"
compile 'org.jooq:jooq:3.11.2'
compile group: 'org.xerial', name: 'sqlite-jdbc', version: "$sqlite_jdbc"
jooqRuntime group: 'org.jooq', name: 'jooq-meta-extensions', version: '3.11.2'
jooqRuntime 'org.xerial:sqlite-jdbc:3.7.2'
sqllite 'org.xerial:sqlite-jdbc:3.7.2'
kapt "io.requery:requery-processor:$requery_version"
compile "com.squareup.retrofit2:retrofit:2.0.0"
compile "com.squareup.retrofit2:converter-moshi:2.0.0"
compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
compile 'com.google.dagger:dagger:2.16'
kapt 'com.google.dagger:dagger-compiler:2.16'
implementation 'com.github.WycliffeAssociates:8woc2018-common:dev-SNAPSHOT'
compile 'com.github.WycliffeAssociates:jdenticon-kotlin:-SNAPSHOT'
compile 'de.jensd:fontawesomefx-commons:9.1.2-jpms'
compile 'de.jensd:fontawesomefx-materialicons:2.2.0-9.1.2-jpms'
compile 'de.jensd:fontawesomefx-icons525:4.2.0-9.1.2-jpms'
compile 'com.github.afester.FranzXaver:Examples:0.1'
compile 'com.jfoenix:jfoenix:8.0.5' // Java 8
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile "org.mockito:mockito-core:2.+"
testCompile "org.mockito:mockito-core:2.+"
testCompile 'org.powermock:powermock-module-junit4:2.+'
testCompile 'org.powermock:powermock-module-junit4-rule:2.+'
testCompile 'org.powermock:powermock-api-mockito2:2.+'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
URLClassLoader loader = GroovyObject.class.classLoader
configurations.sqllite.each { File file ->
loader.addURL(file.toURL())
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
我尝试运行该项目的构建,但出现以下错误:
Caused by: org.gradle.api.InvalidUserDataException: Cannot change strategy of configuration ':sqllite' after it has been resolved.
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.preventIllegalMutation(DefaultConfiguration.java:896)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.validateMutation(DefaultConfiguration.java:867)
at org.gradle.api.internal.artifacts.ivyservice.resolutionstrategy.DefaultCachePolicy.eachModule(DefaultCachePolicy.java:161)
at org.gradle.api.internal.artifacts.ivyservice.resolutionstrategy.DefaultCachePolicy.cacheChangingModulesFor(DefaultCachePolicy.java:121)
at org.gradle.api.internal.artifacts.ivyservice.resolutionstrategy.DefaultResolutionStrategy.cacheChangingModulesFor(DefaultResolutionStrategy.java:190)
at org.gradle.api.internal.artifacts.ivyservice.resolutionstrategy.DefaultResolutionStrategy.cacheChangingModulesFor(DefaultResolutionStrategy.java:186)
at org.gradle.api.artifacts.ResolutionStrategy$cacheChangingModulesFor.call(Unknown Source)
at build_2rl70kyg6ax354v7xbsnpa8n1$_run_closure8.doCall(C:\Users\dipinton\8woc2018-jvm\build.gradle:114)
at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:71)
at org.gradle.util.ConfigureUtil.configureTarget(ConfigureUtil.java:155)
at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:106)
at org.gradle.util.ConfigureUtil$WrappedConfigureAction.execute(ConfigureUtil.java:167)
at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:158)
at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:174)
at org.gradle.api.DomainObjectCollection$all.call(Unknown Source)
at build_2rl70kyg6ax354v7xbsnpa8n1.run(C:\Users\dipinton\8woc2018-jvm\build.gradle:113)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:90)
... 99 more
给我的印象是,我收到的此错误与我有2个配置块有关。一个用于配置我的SQLite模块,另一个用于处理所有模块的解析策略。这两个闭包似乎相互冲突。
有人对消除这两个闭包之间的冲突有任何建议吗?
答案 0 :(得分:1)
这与配置副本上的addUrl一起使用:
def sqliteCopy = configurations.sqlite.copy()
sqliteCopy.each {File file ->
loader.addURL(file.toURI().toURL())
}
代替:
configurations.sqllite.each { File file ->
loader.addURL(file.toURL())
}
或将 com.android.tools.build:gradle 降级到3.1.4版本。