If you import code from somewhere else, that somewhere else is by definition a library. You can’t import a script. If you have such code, there is a place to put it in the automation folder.
In Python you can put your personal library in automation/lib/python. It’s also possible, if a little awkward, to use pip to install third party libraries there.
In JavaScript you can put your personal library in automation/lib/javascript. You can even use those in rules defined through the UI, see OH 3 Examples: Writing and using JavaScript Libraries in MainUI created Rules. The nature of Nashorn and how openHAB uses it makes using third party libraries not quite so easy but still possible in some cases.
The jRuby Helper Libraries (no relation to the Jython/JavaScript libraries) are even available and installed using ruby gems.
The Helper Libraries wouldn’t be a thing if this sort of import were not possible. I don’t know how Groovy works but if there is a limitation on being able to import from the automation/lib/groovy library then that’s a limitation of that language, not a limitation of JSR223 languages in general.