where is the code that copies these JARs to solr?
The dist target in solr/webapp/build.xml depends on lucene-jars-to-solr in solr/common-build.xml, which makes sure that lucene .jar dependencies are built (via prep-lucene-jars), and then copies them to solr/build/lucene-libs/, the contents of which are then packaged into the .war. Dawid, I think this is where you want to make changes.
More packaging details:
The dist target in solr/webapp/build.xml also runs the contribs-add-to-war target from solr/common-build.xml, which invokes add-to-war in each Solr contrib that has a src/webapp/ directory (currently only DIH) to copy the contents of src/webapp/ to solr/build/web/, the contents of which are then packaged into the .war.
Lastly, the create-package target in solr/build.xml depends on the dist target, which depends on the dist-contrib target, which invokes dist in each Solr contrib. Solr contribs that want to include lucene .jar dependencies in the Solr distribution (but not the .war) have their dist targets populate solr/build/contrib/<contrib-name>/lucene-libs/ with those .jars. The create-package target then invokes add-lucene-libs-to-package in each Solr contrib, which copies the contents of solr/build/contrib/<contrib-name>/lucene-libs/ to solr/build/contrib-lucene-libs-to-package/contrib/<contrib-name>/. Finally, the distributions (tarball/zip) include the contents of solr/build/contrib-lucene-libs-to-package/.
Wow, that last part is way more complex than it needs to be. (And it's totally my fault )
Before Robert and I rewrote the Solr build, the top-level Solr build file was huge. One of the guiding principles I used was "keep build configuration local". Now individual modules handle the details that only concern them. Coordination among modules, as seen in the above packaging description, remains a challenge...