based on @daniel-schröter answer you could add a Scheduled Task
following this example:
Go to System -> Tasks
and click Create Task
. Create a script task:
Set the language to groovy
and copy this script modified to fit to scheduled task (you should provide your own modifications to it, it's just an example):
import org.sonatype.nexus.repository.storage.Component
import org.sonatype.nexus.repository.storage.Query
import org.sonatype.nexus.repository.storage.StorageFacet
log.info("delete components for repository: my-repo")
def compInfo = { Component c -> "${c.group()}:${c.name()}:${c.version()}[${c.lastUpdated()}]}" }
def repo = repository.repositoryManager.get("my-repo")
StorageFacet storageFacet = repo.facet(StorageFacet)
def tx = storageFacet.txSupplier().get()
tx.begin()
Iterable<Component> components = tx.findComponents(Query.builder().where('last_updated < ').param('2190-01-01').build(), [repo])
tx.commit()
tx.close()
log.info("about to delete " + components.flatten(compInfo))
for(Component c : components) {
log.info("deleting " + compInfo(c))
tx2 = storageFacet.txSupplier().get()
tx2.begin()
tx2.deleteComponent(c)
tx2.commit()
tx2.close()
}
log.info("finished deleting " + components.flatten(compInfo))