TimefoldAI / timefold-solver

The open source Solver AI for Java, Python and Kotlin to optimize scheduling and routing. Solve the vehicle routing problem, employee rostering, task assignment, maintenance scheduling and other planning problems.
https://timefold.ai
Apache License 2.0
987 stars 87 forks source link

Upgrade from Optaplanner to Timefold failed #273

Closed cbrautigam2 closed 10 months ago

cbrautigam2 commented 1 year ago

Describe the bug I am trying to run the upgrade script to upgrade from Optaplanner 8.x to timefold 0.8. I am using the gradle build instructions here: https://timefold.ai/blog/2023/optaplanner-fork/#upgrade-from-optaplanner-to-timefold. The upgrade failed saying:

No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.rewrite() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl) values: [ai.timefold.solver:timefold-solver-migration:0.8.40]
Possible solutions: wait(), wait(long), create(java.lang.Object), with(groovy.lang.Closure)
> Could not find method rewrite() for arguments [ai.timefold.solver:timefold-solver-migration:0.8.40] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

Expected behavior The upgrade to work without issue

Actual behavior Got the following output from running the upgrade:

[cbrautigam@vm-cbrautigam tasking-service]$ curl https://timefold.ai/product/upgrade/upgrade-timefold08.gradle > upgrade-timefold08.gradle ; gradle -Dorg.gradle.jvmargs=-Xmx2G --init-script upgrade-timefold08.gradle rewriteRun -DtimefoldSolverVersion=0.8.40 ; rm upgrade-timefold08.gradle
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1084  100  1084    0     0   7633      0 --:--:-- --:--:-- --:--:--  7633
Starting a Gradle Daemon (subsequent builds will be faster)

FAILURE: Build failed with an exception.

* Where:
Initialization script '/home/cbrautigam/erudition/services/tasking-service/upgrade-timefold08.gradle' line: 24

* What went wrong:
No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.rewrite() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl) values: [ai.timefold.solver:timefold-solver-migration:0.8.40]
Possible solutions: wait(), wait(long), create(java.lang.Object), with(groovy.lang.Closure)
> Could not find method rewrite() for arguments [ai.timefold.solver:timefold-solver-migration:0.8.40] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 20s

To Reproduce I'm not going to send you our companies spring boot project that caused this issue, but it looks like there is some kind of version issue/conflict being that their seems to be a method signature error.

Environment

Timefold Solver Version or Git ref: 0.8

Output of java -version:

openjdk 11 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)

Output of uname -a or ver:

Linux vm-cbrautigam 4.18.0-372.16.1.el8_6.x86_64 #1 SMP Tue Jun 28 03:02:21 EDT 2022 x86_64 x86_64 x86_64 GNU/Linux

Additional information

This is our build.gradle file contents that has optaplanner dependencies:

dependencies {
    implementation platform("org.optaplanner:optaplanner-bom:8.42.0.Final")
    implementation project(':services-common')
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation('org.springframework.boot:spring-boot-starter-websocket')
    implementation("org.springframework.cloud:spring-cloud-starter-openfeign:3.1.1")
    implementation "org.springframework.boot:spring-boot-starter-hateoas"
    implementation 'com.amazonaws:aws-java-sdk-sqs:1.11.948'
    implementation('com.google.guava:guava:20.0')
    implementation 'org.springframework.cloud:spring-cloud-aws-messaging:2.2.6.RELEASE'
    implementation('org.shredzone.commons:commons-suncalc:3.7')
    implementation "org.optaplanner:optaplanner-core"
    implementation "org.optaplanner:optaplanner-benchmark"

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation project(':services-common-test')
}

jacocoTestReport {
    sourceSets project(':services-common').sourceSets.main
}
cbrautigam2 commented 1 year ago

Gradle Version:

[cbrautigam@vm-cbrautigam tasking-service]$ gradle --version

------------------------------------------------------------
Gradle 8.0.2
------------------------------------------------------------

Build time:   2023-03-03 16:41:37 UTC
Revision:     7d6581558e226a580d91d399f7dfb9e3095c2b1d

Kotlin:       1.8.10
Groovy:       3.0.13
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          11 (Oracle Corporation 11+28)
OS:           Linux 4.18.0-372.16.1.el8_6.x86_64 amd64
triceo commented 1 year ago

Thanks for reporting!

Unfortunately unless I can reproduce the problem, I can not do much about it. When I tried the Gradle migration earlier this month, I was able to complete it on a sample project.

I can only recommend to do the migration by hand. OptaPlanner dependencies need to change to Timefold ones, and org.optaplanner imports need to be replaced by ai.timefold.solver ones. Find&Replace in the IDE should be able to take care of that.

cbrautigam2 commented 1 year ago

Ok well that is very unfortunate, I assume nothing has changed in the script or dependencies since you have tried it?

triceo commented 1 year ago

Ok well that is very unfortunate, I assume nothing has changed in the script or dependencies since you have tried it?

Exactly. I'll give it a go later to double-check.

triceo commented 1 year ago

I was just able to migrate this project: https://github.com/kiegroup/optaplanner-quickstarts/tree/8.x/technology/java-spring-boot

------------------------------------------------------------
Gradle 8.3
------------------------------------------------------------

Build time:   2023-08-17 07:06:47 UTC
Revision:     8afbf24b469158b714b36e84c6f4d4976c86fcd5

Kotlin:       1.9.0
Groovy:       3.0.17
Ant:          Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM:          17.0.8.1 (Eclipse Adoptium 17.0.8.1+1)
OS:           Linux 6.5.2-301.fc39.x86_64 amd64
triceo commented 1 year ago

Also succeeded:

java -version
openjdk version "11.0.19" 2023-04-18
OpenJDK Runtime Environment Temurin-11.0.19+7 (build 11.0.19+7)
OpenJDK 64-Bit Server VM Temurin-11.0.19+7 (build 11.0.19+7, mixed mode)
triceo commented 1 year ago

It appears that some OpenRewrite users on other projects have run into similar problems. The solution was to run the migration from the root of the project, not from the subprojects. (No idea if this applies to your use case though.)

cbrautigam2 commented 1 year ago

yes this is a subproject, i will try running at the root level

cbrautigam2 commented 1 year ago

Still same problem :(

ge0ffrey commented 1 year ago

Looks like the Gradle version is not compatible with the rewrite version. Can you try upgrading from Gradle 8.0.2 to Gradle 8.3 first?

cbrautigam2 commented 1 year ago

I worked around it by just manually upgrading all package names, and my solverConfig.xml. Perhaps the upgrade script needs to check for a min gradle version for compatibility sake? I can talk to our team about a gradle upgrade, but that has greater impacts as we do build online and offline builds and that kind of change is rather pervasive that needs some buy off.

ge0ffrey commented 10 months ago

Shall we close as non-reproducible? Or do we need to validate the minimum gradle version in the migrator somehow?

triceo commented 10 months ago

As we can not reproduce the failure, I'll close it. If more information surfaces, it can be reopened.