Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: StringBundler Incompatible Types Being Imported By ServiceBuilder 7.1.0
After ServiceBuilder successfully generates codes for my project, I noticed the "com.liferay.petra.string.StringBundler" class was imported and used in my -PersistenceImpl files. I successfully added the right dependecy in my build.gradle file to make the Petra StringBundler class available. and then I get compile errors:
Looks like ServiceBuilder is importing the wrong Petra StringBundler class and assigning it in the place where the "com.liferay.portal.kernel.util.StringBundler" class is required. But why is this happening? Below is a copy of my service module's build.gradle with all dependencies:
Please how do I resolve this?
Thanks folks...
C:\Software\Devel\Src\Web\Component\hrm_core\hrm_core-service\src\main\java\com\tpl\pmedics\hrm_core\service\persistence\impl\JobVacancyPersistenceImpl.java:231: error: incompatible types: com.liferay.petra.string.StringBundler cannot be converted to com.liferay.portal.kernel.util.StringBundler
appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
^
C:\Software\Devel\Src\Web\Component\hrm_core\hrm_core-service\src\main\java\com\tpl\pmedics\hrm_core\service\persistence\impl\JobVacancyPersistenceImpl.java:734: error: incompatible types: com.liferay.petra.string.StringBundler cannot be converted to com.liferay.portal.kernel.util.StringBundler
appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
Looks like ServiceBuilder is importing the wrong Petra StringBundler class and assigning it in the place where the "com.liferay.portal.kernel.util.StringBundler" class is required. But why is this happening? Below is a copy of my service module's build.gradle with all dependencies:
apply plugin: "com.liferay.portal.tools.service.builder"
dependencies {
compileOnly group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "3.1.0"
compileOnly group: "com.liferay", name: "com.liferay.portal.spring.extender.api", version: "3.0.0"
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "3.0.0"
compileOnly group: "com.liferay", name: "com.liferay.petra.function", version: "2.0.0"
compileOnly group: "com.liferay", name: "com.liferay.petra.model.adapter", version: "2.0.0"
compileOnly group: "com.liferay", name: "com.liferay.petra.reflect", version: "2.0.0"
compileOnly group: "com.liferay", name: "com.liferay.petra.string", version: "2.0.0"
compileOnly group: "com.liferay", name: "com.liferay.portal.dao.orm.custom.sql.api", version: "1.0.0"
compileOnly group: "javax.portlet", name: "portlet-api", version: "3.0.0"
compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1"
compileOnly group: "org.osgi", name: "org.osgi.core", version: "5.0.0"
compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations", version: "1.3.0"
compileOnly project(":hrm_core-api")
}
buildService {
apiDir = "../hrm_core-api/src/main/java"
}
group = "com.tpl.pmedics.hrm_core"
Please how do I resolve this?
Thanks folks...
David Ilechukwuerror: incompatible types: com.liferay.petra.string.StringBundler cannot be converted to com.liferay.portal.kernel.util.StringBundler
From that error, it sounds like you're using a newer version of service builder from after LPS-78938 (which is a change that requires version 3.23.0 of com.liferay.portal.kernel or higher), while compiling against version 3.0.0 of com.liferay.portal.kernel.
If you're using a DXP fix pack (the change to BasePersistenceImpl is not available until dxp-1) or you're using a nightly snapshot of 7.1.x for development testing, then you can update your dependency version of com.liferay.portal.kernel. If you're using 7.0 GA1, or you're using the original 7.1 DXP release, you'll need to downgrade your version of com.liferay.portal.tools.service.builder to 1.0.237 or earlier (before the changes were made to service builder to use the petra version of StringBundler).
Thanks Minhchau! Your reply was really a lifesaver. There was really no way I could have figured that out!
Please I am using
My declared liferay.portal.kernell dependency is 3.0.0 like this
I can also see two versions of com.liferay.portal.tools.service.builder in my gradle lib - version 1.0.237 and 1.0.244. Which version should I use please?
Please I am using
[color=inherit][font=inherit][size=3]Liferay Community Edition Portal 7.1.0 CE GA1 (Judson / Build 7100 / July 2, 2018)[/size][/font][/color]
My declared liferay.portal.kernell dependency is 3.0.0 like this
[color=inherit][font=inherit][size=3]compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "3.0.0"[/size][/font][/color]
I can also see two versions of com.liferay.portal.tools.service.builder in my gradle lib - version 1.0.237 and 1.0.244. Which version should I use please?
I can also see two versions of com.liferay.portal.tools.service.builder in my gradle lib - version 1.0.237 and 1.0.244. Which version should I use please?
Just to make sure, I double-checked the commit history, and I misread the commit history when I wrote my earlier post. The version was incremented to 1.0.237 after LPS-78938 (reference commit), not before it.
You'll need to switch to the Service Builder 7.0 DTD on your service.xml, or you'll want to use 1.0.236 or earlier of com.liferay.portal.tools.service.builder.
Solution 1: Change service builder DTD
The breaking change is that the service builder plugin thinks that all versions of 7.1 have the petra StringBundler method, when this is essentially invalid. One way to work around it is to update your service.xml to use the 7.0 DTD instead. Liferay will naively believe that your plugin is for 7.0, and it won't use the petra StringBundler method.
Solution 2: Downgrade Liferay workspace plugin
The breaking change occurs in the release of 1.0.237 of the service builder tools dependency.
If you're using version 1.10.6 or later of the Liferay workspace plugin, the transitive dependencies ultimately pull in version 1.0.244 of com.liferay.portal.tools.service.builder, and while upgrading is fairly straightforward, it's not obvious how to downgrade dependencies in Gradle.
However, if you're using version 1.10.5 of the Liferay workspace plugin, it uses version 1.0.235 of the service builder tools dependency, which won't have the regression. You downgrade the Liferay workspace plugin by updating settings.gradle, found at the root of your Liferay workspace.
buildscript {
dependencies {
classpath group: "com.liferay", name: "com.liferay.gradle.plugins.workspace", version: "1.10.5"
}
// ...
}
Solution 3: Switch the dependency version
Downgrading the dependency version requires you to update all configurations to use the older version of service builder, as described in Customizing Dependency Resolution Behavior in the Gradle documentation. You update these configurations by updating build.gradle, found at the root of your Liferay workspace.
subprojects { subproject ->
// ...
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'com.liferay' && details.requested.name == 'com.liferay.portal.tools.service.builder') {
details.useVersion '1.0.236'
details.because 'Downgrade dependency to work around regression introduced in LPS-78938'
}
}
}
// ...
}
Thank you so much Minhchau for this wonderful summary.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™