composer vendor override – Cannot declare class because the name is already in use

I needed to modify some vendor files, which I did the following way (which was fine in the past):

I copy the vendor file to a vendor-override directory outside the vendor directory and modify it to my needs. Then modify composer.json by adding the original vendor file to “exclude-from-classmap” and add my file to “files”

example:

    "autoload": {
        "psr-4": {
            "App\": "app/",
            "Database\Factories\": "database/factories/",
            "Database\Seeders\": "database/seeders/",
            "Routes\Web\": "routes/web/"
        },
        "exclude-from-classmap": [
            "vendor/area17/twill/src/Models/Model.php",
            "vendor/area17/twill/src/Models/Media.php"
        ],
        "files": [
            "vendor-override/twill/Model.php",
            "vendor-override/twill/Media.php"
        ]
    },

Now my problem is, that “vendor/area17/twill/src/Models/Media.php” inherits from “vendor/area17/twill/src/Models/Model.php”

If I run composer dump-auto, I get the following error:

PHP Fatal error:  Cannot declare class A17TwillModelsModel, because the name is already in use in C:DatabaseSourceDBmodulbau-shopvendor-overridetwillModel.php on line 23

I also tried deleting the vendor Model.php and Media.php file (for testing):
Then I get the following error instead:

In Media.php line 12:
                                            
  [Error]                                   
  Class "A17TwillModelsModel" not found  
                                            

Exception trace:
  at C:DatabaseSourceDBmodulbau-shopvendor-overridetwillMedia.php:12
 require() at C:DatabaseSourceDBmodulbau-shopvendorcomposerautoload_real.php:41
 {closure}() at C:DatabaseSourceDBmodulbau-shopvendorcomposerautoload_real.php:45

To me it seems that vendor-override/twill/Media.php is still referencing to the file in vendor for some reason (perhaps because they were originally in the same folder?)

I tried adding an explicit import (use statement to the Media file, but it did not help. I still get the Class "A17TwillModelsModel" not found error)

vendor-override/twill/Media.php

<?php

namespace A17TwillModels;

use A17TwillModelsModel; // I added this line
use A17TwillServicesMediaLibraryImageService;
use AppModelsSubdomain;
use IlluminateSupportCollection;
use IlluminateSupportFacadesDB;
use IlluminateSupportStr;

class Media extends Model {
  ...

I don’t really understand why it still tries to reference the vendor file, when I explicitly excluded that one from the classmap. Any ideas how to fix that?