Later, in the context of the Portuguese Restoration War, John VI of Portugal (1640–1656) confirmed all the privileges granted to Tavira by his predecessors, determining works to modernize the medieval castle, reinforcing its structure and adapting it to the shots of the then modern artillery. The defense of the village was complemented, in 1672, by the beginning of the construction of the São João da Barra de Tavira Fortress, in Gomeira, bordering the Gilão river in 1717.